如何在 Google Maps V3 中创建带编号的地图标记? [英] How can I create numbered map markers in Google Maps V3?

查看:35
本文介绍了如何在 Google Maps V3 中创建带编号的地图标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一张上面有多个标记的地图.

I'm working on a map that has multiple markers on it.

这些标记使用自定义图标,但我还想在顶部添加数字.我已经看到这是如何使用旧版本的 API 来完成的.我怎样才能在 V3 中做到这一点?

These markers use a custom icon, but I'd also like to add numbers on top. I've seen how this has been accomplished using older versions of the API. How can I do this in V3?

*注意 -- 当您将鼠标悬停在标记上时,标题"属性会创建一个工具提示,但我希望即使您没有将鼠标悬停在自定义图像上,它也会分层放置在自定义图像上.

*Note -- the "title" attribute creates a tooltip when you mouseover the marker, but I want something that will be layered on top of the custom image even when you're not hovering on top of it.

这是标记类的文档,这些属性似乎都没有帮助:http://code.google.com/apis/maps/documentation/v3/reference.html#MarkerOptions

Here's the documentation for the marker class, and none of these attributes seem to help: http://code.google.com/apis/maps/documentation/v3/reference.html#MarkerOptions

推荐答案

不幸的是这并不容易.您可以基于 OverlayView 类创建自己的自定义标记(一个示例) 并将您自己的 HTML 放入其中,包括一个计数器.这将为您留下一个非常基本的标记,您无法轻松拖动或添加阴影,但它非常可定制.

Unfortunately it's not very easy. You could create your own custom marker based on the OverlayView class (an example) and put your own HTML in it, including a counter. This will leave you with a very basic marker, that you can't drag around or add shadows easily, but it is very customisable.

或者,您可以添加标签到默认标记.这将不太可定制,但应该可以工作.它还保留了标准标记所做的所有有用的事情.

Alternatively, you could add a label to the default marker. This will be less customisable but should work. It also keeps all the useful things the standard marker does.

您可以在 Google 的文章玩转 MVC 对象

You can read more about the overlays in Google's article Fun with MVC Objects.

如果您不想创建 JavaScript 类,可以使用 Google 的图表 API.例如:

if you don't want to create a JavaScript class, you could use Google's Chart API. For example:

编号标记:

http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=7|FF0000|000000

文本标记:

http://chart.apis.google.com/chart?chst=d_map_spin&chld=1|0|FF0000|12|_|foo

这是一种快速简便的方法,但它的可定制性较差,并且需要客户端为每个标记下载一个新图像.

This is the quick and easy route, but it's less customisable, and requires a new image to be downloaded by the client for each marker.

这篇关于如何在 Google Maps V3 中创建带编号的地图标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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