简体   繁体   English

Google Maps Javascript API自定义标记号

[英]Google Maps Javascript API custom marker number

I am using custom images for my markers using google maps javascript api V3 and I was wondering if anyone knows how to super impose a number on top of those. 我使用谷歌地图javascript api V3为我的标记使用自定义图像,我想知道是否有人知道如何超级强加一个数字在那些之上。 I have a box image and I need to dynamically place a number in the box. 我有一个盒子图像,我需要动态地在框中放置一个数字。 I don't know if there is a style way of doing this or if someone can tell me how to do it via javascript. 我不知道是否有这样做的风格方式,或者有人可以通过javascript告诉我如何做到这一点。

You can use maps utility library ( http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries ). 您可以使用地图实用程序库( http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries )。 RichMarker & styledMarker (scroll down the page) are probably most useful to you. RichMarker&styledMarker(向下滚动页面)可能对您最有用。

Option 2 - you can roll your own implementing overlay class (a bit of work required). 选项2 - 您可以滚动自己的实现覆盖类(需要一些工作)。 Example is here http://gmaps-samples-v3.googlecode.com/svn/trunk/overlayview/custommarker.html 示例在这里http://gmaps-samples-v3.googlecode.com/svn/trunk/overlayview/custommarker.html

Option 3 - (more tedious) is to create custom marker images with numbers on them. 选项3 - (更乏味)是创建带有数字的自定义标记图像。

Support for single character marker labels was added to Google Maps in version 3.21 (Aug 2015). 3.21版(2015年8月)的Google地图添加了对单字符标记标签的支持。 See the new marker label API . 查看新的标记标签API Unfortunately, this is limited to single digits , so if you need 2+ digit numbers, you will still need to use an add on library like RichMarker. 不幸的是,这仅限于个位数 ,因此如果您需要2位数字,您仍需要使用像RichMarker这样的附加库。

You can now create your label marker like this: 您现在可以像这样创建标签标记:

var marker = new google.maps.Marker({
  position: new google.maps.LatLng(latitude, longitude), 
  icon: markerIcon,
  label: {
    text: '1'
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM