2016-09-20 48 views

回答

5

你可以使用标题作为密钥存储的标记在Map<String Marker>

private Map<String, Marker> markers = new HashMap<>(); 

当你添加标记到地图上,你还需要将它们添加到HashMap中:

String markerTitle = "My Marker"; 
LatLng markerPosition = new LatLng(26.89454, 75.82607); 
Marker marker = mMap.addMarker(new MarkerOptions().position(markerPosition).title(markerTitle)); 
markers.put(markerTitle, marker); // Add the marker to the hashmap using it's title as the key 

然后你就可以居中你的标记查询到散:

private void centerMarker(String title) { 
    Marker marker = markers.get(title); 
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15f)); 
} 
+0

和先生做ü有反正如果我取标记名称,从服务器中纬度和经度我又如何能做到这一点一样呢? –

+0

你也可以这样做,你只需要从服务器获取数据并从那里设置位置和标题 – antonio

+0

HashMap marker = result.get(i); –