javascript 谷歌地图中自定义标记的编号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21474452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Numbering on Custom markers in Google Map
提问by Nishant Nawarkhede
I am using google map for showing locations.
我正在使用谷歌地图显示位置。
My requirement is that each and every location is labelled with numbers.
我的要求是每个位置都标有数字。
Currently using this code ,
目前使用此代码,
for (var i = 0; i < data.length; i++){
var image = new google.maps.MarkerImage(
'{{STATIC_URL}}img/icon-pin'+(i+1)+'.png',
new google.maps.Size(68, 49),
new google.maps.Point(0,0),
new google.maps.Point(19, 49));
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data[i].lat, data[i].lon),
map: map,
icon:image,
});
}
Here with respect to i , new image is fetched from img folder like ,i=0
image will be img/icon-pin1.png
i=1
image will be img/icon-pin2.png
这里关于 i ,新图像是从 img 文件夹中获取的,i=0
图像将是img/icon-pin1.png
i=1
图像将是img/icon-pin2.png
I know it is not proper way to placing numbered markers in map.
我知道在地图中放置编号标记不是正确的方法。
My custom marker is like,
我的自定义标记就像,
How can i add numbers to this image, while inserting marker.
如何在插入标记时向该图像添加数字。
Expected result,
预期结果,
采纳答案by MrUpsidown
As stated in my comment, a few solutions are available and depicted here: How can I create numbered map markers in Google Maps V3?
正如我的评论中所述,这里提供了一些解决方案并进行了描述:如何在 Google Maps V3 中创建编号的地图标记?
Another way would be to manipulate the marker image with PHP (if this is an option) as explained in this answer: https://stackoverflow.com/a/20778505/1238965
另一种方法是使用 PHP 操作标记图像(如果这是一个选项),如本答案所述:https: //stackoverflow.com/a/20778505/1238965
The above example shows how to change the background of the image, but you could also add some text with the use of imagettftext.
上面的示例显示了如何更改图像的背景,但您也可以使用imagettftext添加一些文本。
Hope this helps!
希望这可以帮助!