【问题标题】:Google Maps API v3 - GIcon is not definedGoogle Maps API v3 - 未定义 GIcon
【发布时间】:2012-06-04 15:42:18
【问题描述】:

我知道它们是从 v2 到 v3 的一些问题,我可以在这里做些什么来解决它?
v3 不支持 GIcon?

// 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);

从这里找到https://developers.google.com/maps/documentation/javascript/overlays?hl=de-DE#SimpleIcons

感谢任何帮助或提示!

【问题讨论】:

    标签: google-maps google-maps-api-3 google-api google-maps-markers google-maps-api-2


    【解决方案1】:

    GIcon 不受版本 3 支持,并且不会出现在您链接到的文档中。

      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
      });
    

    您可以指定要直接使用的图像,您不需要像版本 2 的 GIcon 这样的帮助对象。但是,如果您想要非标准尺寸等,则需要使用 MarkerImage 对象,如 https://developers.google.com/maps/documentation/javascript/overlays?hl=de-DE#ComplexIcons 文档中所述

    (版本 2 的 GIcon 等效于版本 3 中的可选 MarkerImage

    【讨论】:

      猜你喜欢
      • 2011-02-19
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 2012-06-07
      • 2013-11-12
      • 2014-03-05
      相关资源
      最近更新 更多