1

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?

2 Answers 2

1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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