【问题标题】:Google maps - custom marker with number谷歌地图 - 带有数字的自定义标记
【发布时间】:2013-05-20 01:07:21
【问题描述】:

我目前正在使用以下代码显示标记:

var marker = new google.maps,Marker({
  map: maps,
  position: coordinate,
  icon: 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld='+ (position) +'|FF776B|000000',
});

这会显示带有数字的默认地图标记。

问题是,你能不能有一个自定义图标,比如说marker.png 然后覆盖一个数字?

谢谢

【问题讨论】:

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


    【解决方案1】:

    像这样指定你的标记:

    var myLatLng = new google.maps.LatLng(lat, long);
    var myOptions = {
      zoom: 4,
      center: myLatLng,
      mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    
    var styleMaker1 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:"00ff00",text:"1"}),position:myLatLng,map:map});
    

    【讨论】:

    【解决方案2】:

    使用 ma​​rkerWithLabel.js 库...

    代码如下:

    marker = new MarkerWithLabel({
                map: maps,
                position: coordinate,
                icon : yourMarkerImage,
                labelContent : yourNumberOnMarker,
                labelAnchor : yourLabelPosition,     // e.g. new google.maps.Point(21, 10);
                labelClass : "labels",          // the CSS class for the label
                labelInBackground : false
            });
    

    【讨论】:

      【解决方案3】:

      我一直在研究这个,并使用了 Google Charts API,但是如果您想要一个基于 png 的自定义标记,例如,您可以通过 PHP 和图像库根据您的参数返回自定义标记,类似于如何您正在调用的 Google Charts API。

      【讨论】:

        猜你喜欢
        • 2016-09-20
        • 2015-01-28
        • 2013-08-21
        • 2014-10-11
        • 2016-02-06
        • 1970-01-01
        • 2017-06-04
        相关资源
        最近更新 更多