开发者

Google Map Marker + JQuery: Change icon

开发者 https://www.devze.com 2023-01-12 19:22 出处:网络
If I already displayed a google m开发者_运维问答ap marker. How could I change its icon using Jquery?

If I already displayed a google m开发者_运维问答ap marker.

How could I change its icon using Jquery?

Thanks in advance.


Actually Google Maps API has supported method to setImage for marker. I get this code from Google Code PlayGround (http://code.google.com/apis/ajax/playground/#custom_marker_image_v3)

function initialize() {
  var mapDiv = document.getElementById('map-canvas');
  var latLng = new google.maps.LatLng(37.4419, -122.1419);
  var map = new google.maps.Map(mapDiv, {
    center: latLng,
    zoom: 13,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var image = 'http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag.png';
  var myLatLng = new google.maps.LatLng(-33.890542, 151.274856);
  var beachMarker = new google.maps.Marker({
    position: latLng,
    map: map,
    icon: image
  });
}
0

精彩评论

暂无评论...
验证码 换一张
取 消