我需要在 android Google mapV2 中创建自定义路线。
如下图所示。
截至目前,我能够通过 json 请求获取两个 latlng 之间的路由,但没有找到任何修改它的方法。
最佳答案
您可以通过这种方式实现:首先将 options.draggable(true);
设置为您添加的 Marker
MarkerOptions options = new MarkerOptions();
// Setting the position of the marker
options.position(point);
options.draggable(true);
if(markerPoints.size()==1){
options.title("Marker1");
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
}else if(markerPoints.size()==2){
options.title("Marker2");
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
}
// Add new marker to the Google Map Android API V2
map.addMarker(options);
现在,将 setOnMarkerDragListener(new OnMarkerDragListener(){...}
实现到您的 Activity
中,例如:
map.setOnMarkerDragListener(new OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker arg0) {
// TODO Auto-generated method stub
}
@Override
public void onMarkerDragEnd(Marker marker) {
// TODO Auto-generated method stub
LatLng dragPosition = marker.getPosition();
double dragLat = dragPosition.latitude;
double dragLong = dragPosition.longitude;
Toast.makeText(Main3.this, "After onMarkerDragEnd position: "+ dragLat+" "+dragLong,Toast.LENGTH_LONG).show();
}
@Override
public void onMarkerDrag(Marker arg0) {
// TODO Auto-generated method stub
}
});
}
在 onMarkerDragEnd(....)
中,您可以通过标题和在新点和旧点之间再次绘制路线来识别 Marker
。
关于android - 如何通过在 android Google MapV2 中拖动标记来创建自定义路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22067415/