[GIS] Google Maps Markers inconsistent as they’re drawn

google maps

I've playing around with the google maps api and am puzzled at the following behavior. If I use mPoint as the LatLng for my marker, the marker is rendered on a different point on the map as opposed to putting the same value directly into the properties of the marker. Code chunk is as follows:

        var mPoint = [new google.maps.LatLng(38.991300,-76.936165)];
//        var GPoint = new google.maps.Marker({map:map,position:AVPoint});
  var marker = new google.maps.Marker({
    map: map,
    position: new google.maps.LatLng(38.991300,-76.936165),
    //position: new google.maps.LatLng(mPoint),
    draggable: true
  });

Why would this happen?

Best Answer

In your code:

var mPoint = [new google.maps.LatLng(38.991300,-76.936165)];

You define an array as mPoint. And it absolutely makes no sense to pass this array to the marker object that you are creating since the position attribute expects a latlng object and not an array as argument.

In your case var marker = new google.maps.Marker({map: map,position: mPoint[0], draggable: true}); would be the solution.