[英]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.