Google地图MarkerWithLabel和自定义图标工作不正常 [英] Google Maps MarkerWithLabel and custom Icon not working correctly

查看:328
本文介绍了Google地图MarkerWithLabel和自定义图标工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的谷歌地图,我试图使用MarkerWithLabel扩展插件添加标记。我必须从json对象加载坐标,并且在标签上我必须放置标记的排序顺序,这也来自json。



问题在于我为标记加载的自定义图标只适用于最后一个,我无法弄清楚原因。他们都定位正确,但其他人没有图标。



以下是我用来添加标记的功能:

 函数CreateTourMarkers(json){
if(json.length> 0){
json.forEach(function(item){
var myCoord = new google.maps.LatLng(item.Lat,item.Lng);
var marker = new MarkerWithLabel({
position:myCoord,
map:vehiclesMap,
图标:{
url:image
},
labelContent:item.SortOrder,
labelAnchor:新增google.maps.Point(5,37),
labelClass:map-labels,
marker:MarkerWithLabel,
labelInBackground:false
});
});
}
}

这里还有一个提示问题的小提琴:小提琴



任何帮助将不胜感激。

谢谢

解决方案

我更新了小提琴以使用v1。 1.9的markerwithlabel.js,它显示所有标记上的自定义图标,所以我假设它必须是v1.1.8的bug。


I have a basic google map on which I'm trying to add markers using the MarkerWithLabel extension. I have to load the coordinates from a json object, and on the label I have to put the sort order of the markers, which is also from the json.

The problem is that the custom icon I load for the markers only works on the last one and I can't figure out why. They all position correctly, but the other ones do not have an icon.

Here is the function I used to add the markers :

function CreateTourMarkers(json) {
    if (json.length > 0) {
        json.forEach(function (item) {
            var myCoord = new google.maps.LatLng(item.Lat, item.Lng);
            var marker = new MarkerWithLabel({
                position: myCoord,
                map: vehiclesMap,
                icon: {
                    url: image
                },
                labelContent: item.SortOrder,
                labelAnchor: new google.maps.Point(5, 37),
                labelClass: "map-labels",
                marker: MarkerWithLabel,
                labelInBackground: false
            });
        });
    }
}

Also here is a fiddle showing the problem : fiddle

Any help would be greatly appreciated.

Thanks

解决方案

I updated your Fiddle to use the v1.1.9 of markerwithlabel.js and it shows the custom icon on all markers so I'm assuming it must be a bug with v1.1.8.

这篇关于Google地图MarkerWithLabel和自定义图标工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆