Google Maps API v3 - GIcon is not defined

我是研究僧i 提交于 2019-12-21 07:56:33

问题


I know they are some issues from v2 to v3 what can i do here to fix it?
GIcon is not supported by v3?

// Google-Map icon object
var gMapIcon = new GIcon(G_DEFAULT_ICON); //change to new google.maps.MarkerImage();???
// does icon exist
if ( mapElements[lMapElementIndex]['icon'].toString().length > 0) {
    gMapIcon.image = html_entity_decode(mapElements[lMapElementIndex]['icon']);
    gMapIcon.shadow = "";
    iconHeight = mapElements[lMapElementIndex]['iconheight'];
    iconWidth = mapElements[lMapElementIndex]['iconwidth'];
    gMapIcon.iconSize = new GSize(iconWidth,iconHeight);
    gMapIcon.iconAnchor = new GPoint(0,0);
    gMapIcon.infoWindowAnchor = new GPoint(15,10);
}
    var markerOptions = { 
        icon: gMapIcon //change to image? 
     };
    var marker = new google.maps.Marker(point,markerOptions);

found from here https://developers.google.com/maps/documentation/javascript/overlays?hl=de-DE#SimpleIcons

thanks for any help or tips!


回答1:


GIcon is not supported by Version 3, and does not appear in the documentation you link to.

  var image = 'beachflag.png';
  var myLatLng = new google.maps.LatLng(-33.890542, 151.274856);
  var beachMarker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      icon: image
  });

You can specify an image to use directly, you don't need a helper object like Version 2's GIcon. However, if you want non-standard sizes etc you will need to use a MarkerImage object as described in the documentation at https://developers.google.com/maps/documentation/javascript/overlays?hl=de-DE#ComplexIcons

(Version 2's GIcon has its equivalent as the optional MarkerImage in Version 3)



来源:https://stackoverflow.com/questions/10884085/google-maps-api-v3-gicon-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!