简体   繁体   English

如何在谷歌地图静态api中的标记上显示标签(字符串)?

[英]How to show a label(String) over a marker in google maps static api?

I am working on a vehicle routing algorithm I need to show vehicles on maps with there driver name on top of the label.我正在研究一种车辆路线算法,我需要在地图上显示车辆,标签顶部有司机姓名。 I have done the marker part it looks like this.我已经完成了看起来像这样的标记部分。在此处输入图片说明

However I would like to display driver's name on top of every marker.但是我想在每个标记的顶部显示驱动程序的名字。 Can you suggest me any way to do it?你能给我建议任何方法吗?

My google maps static api url looks like this我的谷歌地图静态 api url 看起来像这样

https://maps.googleapis.com/maps/api/staticmap?center=26.900,75.800&zoom=11&size=400x400&markers=color:blue|label:Driver|&markers=color:green|label:Req|26.925571778374632,75.81166033197894|&markers=color:blue|label:others|26.944421737574313,75.8072312248272|26.941722318252367,75.82851178160593|26.909618922760885,75.85079885210592|26.92537722447672,75.85626510000787|26.969253598622025,75.81687986464266|26.933707124740607,75.84999920863306|26.986333832648626,75.88755301718626|26.945330532812793,75.81567681826434|26.942938812152843,75.81989078933901|&markers=color:red|label:Req|26.8983489,75.796436|

Ps: I am using java. ps:我用的是java。

I think the best you can do with the Static Maps API v2 is to have different initials and colors for different markers.我认为使用 Static Maps API v2 可以做的最好的事情是为不同的标记使用不同的首字母和颜色。 Like this example .这个例子

You may be able to do something with the custom icons too, but it does not seem to be working as far as I can tell.您也可以使用自定义图标做一些事情,但据我所知,它似乎不起作用。

The best practice here is to implement it using the JavaScript API v3 instead.此处的最佳实践是使用JavaScript API v3来实现它。

Is this possible with the version you're using?您使用的版本是否可以做到这一点?

@Override
public void onMapReady(GoogleMap map) {
    LatLng sydney = new LatLng(-33.867, 151.206);

    map.setMyLocationEnabled(true);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));

    map.addMarker(new MarkerOptions()
            .title("Sydney")
            .snippet("The most populous city in Australia.")
            .position(sydney));
}

Here is the code in action: https://developers.google.com/maps/documentation/android/这是正在运行的代码: https : //developers.google.com/maps/documentation/android/

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

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