【发布时间】:2018-07-14 09:25:58
【问题描述】:
我有 3 个点想要绘制 折线,但折线不可见。
首先,地图上有 3 个标记,所以我尝试用 polyline 将它们加入,但它拒绝了,对我来说代码看起来不错,但折线不可见, 如何改进我的代码。
下面是我的代码:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpClusterer(mMap);
}
//clustered map
private void setUpClusterer(GoogleMap mMap) {
// Position the map.
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-23.684, 133.903), 4));
// Initialize the manager with the context and the map.
// (Activity extends context, so we can pass 'this' in the constructor.)
mClusterManager = new ClusterManager<MyItem>(this, mMap);
// Point the map's listeners at the listeners implemented by the cluster
// manager.
mMap.setOnCameraIdleListener(mClusterManager);
mMap.setOnMarkerClickListener(mClusterManager);
// Add cluster items (markers) to the cluster manager.
addItems(mMap);
}
private void addItems(GoogleMap mMap) {
// Set some lat/lng coordinates to start with.
double lat = 51.5145160;
double lng = -0.1270060;
HashMap<Double,Double> hm = new HashMap<>();
/* new LatLng(-34.747, 145.592),
new LatLng(-34.364, 147.891),
new LatLng(-33.501, 150.217),*/
hm.put(-34.747,145.592);
hm.put(-34.364,147.891);
hm.put(-33.501,150.217);
// Add ten cluster items in close proximity, for purposes of this example.
for(Map.Entry m:hm.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
MyItem offsetItem = new MyItem(Double.parseDouble(m.getKey().toString()),Double.parseDouble(m.getValue().toString()));
mClusterManager.addItem(offsetItem);
Polyline polyline = mMap.addPolyline(new PolylineOptions()
.clickable(true)
.add(
new LatLng(Double.parseDouble(m.getKey().toString()), Double.parseDouble(m.getValue().toString()))
));
stylePolyline(polyline);
}
}
【问题讨论】:
标签: java android google-maps google-maps-markers google-polyline