如何在谷歌地图静态API中的标记上显示标签(String)?

时间:2015-06-15 07:32:41

标签: java google-maps google-maps-api-3

我正在开发一种车辆路线算法,我需要在地图上显示车辆,并在标签顶部显示驱动程序名称。我做了标记部分看起来像这样。 enter image description here

但是我想在每个标记的顶部显示驱动程序的名称。你能告诉我任何办法吗?

我的google maps static 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:我正在使用java。

2 个答案:

答案 0 :(得分:1)

我认为使用Static Maps API v2可以做的最好的事情就是为不同的标记设置不同的首字母和颜色。与this example一样。

您也可以使用custom icons执行某些操作,但似乎无法正常工作。

此处的最佳做法是使用JavaScript API v3来实现它。

答案 1 :(得分:0)

您使用的版本是否可以使用?

@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));
}

以下是操作中的代码:https://developers.google.com/maps/documentation/android/