Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

Google Maps Marker Example (with drop/drag animation) reference: https://developers.google.com/maps/documentation/javascript/examples/

<script>
  var mPoint = new google.maps.LatLng(38.991300,-76.936165);
  var marker;
  var map;

  function initialize() {
    var mapOptions = {
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: mPoint
    };

    map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);

    marker = new google.maps.Marker({
      map:map,
      draggable:true,
      animation: google.maps.Animation.DROP,
      position: mPoint
    });
    google.maps.event.addListener(marker, 'click', toggleBounce);
  }

  function toggleBounce() {

    if (marker.getAnimation() != null) {
      marker.setAnimation(null);
    } else {
      marker.setAnimation(google.maps.Animation.BOUNCE);
    }
  }
</script>

Source: https://google-developers.appspot.com/maps/documentation/javascript/examples/marker-animations

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.