【问题标题】:Marker with image and number in google maps api谷歌地图 api 中带有图像和数字的标记
【发布时间】:2014-01-19 01:41:15
【问题描述】:

我正在使用 gmap .. 我想在地图上放置一些标记,标记图标是动态的,我还希望使用图标显示“数字”,这可能吗.. 我的代码是

function putMaker(position, title, title_dis, number, icon_img)
{
    if (!isNaN(number))
        var icon = "https://chart.googleapis.com/chart?chst=d_bubble_icon_text_small&chld=ski|bb|" + number + "|FFFFFF|000000";
    else
        var icon = null;
    var marker = new google.maps.Marker({
        position: position,
        map: map,
        icon: icon_img,
        shadow: icon,
    });
    google.maps.event.addListener(marker, 'mouseover', function() {
        infowindow.setContent(title_dis);
        infowindow.open(map, this);
    });
}

而图标是

var icon_img = new google.maps.MarkerImage(
        "<?php echo  base_url().'timthumb.php?src='.$url.'&h=32&w=50'; ?>", //url
        new google.maps.Size(50, 32), //size
        new google.maps.Point(0, 0), //origin
        new google.maps.Point(0, 32) //anchor 
        );

【问题讨论】:

    标签: javascript php google-maps google-maps-api-3


    【解决方案1】:

    使用 markerwithlabel library 完全可以。您可以通过添加icon参数来修改one of the basic examples(您可以添加任何standard google.maps.Marker options):

    var marker = new MarkerWithLabel({
       position: homeLatLng,
       map: map,
       draggable: true,
       raiseOnDrag: true,
       labelContent: "2", // your number
       icon: "img/your_icon.png",
       labelAnchor: new google.maps.Point(3, 30),
       labelClass: "labels", // the CSS class for the label
       labelInBackground: false
     });
    

    http://jsfiddle.net/Vug7W/

    【讨论】:

      猜你喜欢
      • 2016-02-06
      • 2015-04-25
      • 2011-10-09
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      相关资源
      最近更新 更多