The below sets a marker if I hard-code the latitude and longitude.

I want to instead pass it dynamically using place (an associative array) but I can't seem to make it work (I get errors saying I need to pass a number). I'm suspecting that I'm accessing the array incorrectly but can't find the right permutation of quotes and braces.

Any thoughts?

     * Adds marker for place to map.
    function addMarker(place)

        // alert (JSON.stringify(place.latitude));

        // TODO
        var myLatLng = {lat: place["latitude"], lng: place["longitude"]};
        // var myLatLng = {lat: place.latitude, lng: place.longitude};

        // console.log(place);
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            title: "Hello, world!"
  • 1
    what changes did u make in your code other than the the one in the answer which made it work because i wrote the same lines of code but there is no sign of marker on my map..:(
    – Aditi
    Apr 17, 2016 at 17:48

1 Answer 1


As far as I can tell, the issue is that the is being passed in as a string. So I turned them into floats by doing the following (using parseFloat):

        var mylat = parseFloat(place.latitude);
        var mylng = parseFloat(place.longitude);

        // TODO
        var myLatLng = {lat: mylat, lng: mylng};

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .