繁体   English   中英

具有Google地图动态编号的自定义图标标记

[英]Custom icon marker with dynamic numbering for Google maps

我已经看到了许多在标记图标上动态生成数字的示例。 我发现的其中之一是Google Chart API。 部分解决了我的问题。 如下所示,我在编辑代码后能够生成数字。
但是是否可以添加这样的自定义图标 然后生成数字吗?

function addMarker(id,location,address,facility,name,ratings) 
    {


        marker = new google.maps.Marker(
        {
            position: location,
            map: map,
            animation:  google.maps.Animation.DROP,
            icon: 'https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld='+id+'|FF776B|000000',
             shadow:'https://chart.googleapis.com/chart?chst=d_map_pin_shadow'
        });

此图表API现在已弃用,并且Google将根据其修订后的“条款和条件”仅提供一年的支持。

我认为最好的方法是在服务器端创建标记。 如果您的应用程序需要显示有限数量的标记(例如一次最多显示25个),则可以在服务器上显示它们。 可用Java或任何其他编程语言提供图像处理工具。

这是使用Java的一小段代码。

BufferedImage image = null;
try {
   image = ImageIO.read(new File("/path/to/base/icon"));
} catch (IOException e) {
   e.printStackTrace();
}

Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(30f));
g.drawString("1", x, y);  // x,y are points where you want to add the number
g.dispose();

try {
    ImageIO.write(image, "png", new File("test.png"));
} catch (IOException e) {
    e.printStackTrace();
}

您可以使用for循环创建所需数量的编号标记。

暂无
暂无

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

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