当用户开始向任何方向移动时,我想在运行时在 map 上绘制线(路径)。
现在我可以像这样静态地在两点之间画一条线 -
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
md = new GMapV2Direction();
mMap = ((SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
LatLng coordinates = new LatLng(13.685400079263206, 100.537133384495975);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 16));
mMap.addMarker(new MarkerOptions().position(fromPosition).title("Start"));
mMap.addMarker(new MarkerOptions().position(toPosition).title("End"));
Document doc = md.getDocument(fromPosition, toPosition, GMapV2Direction.MODE_WALKING);
int duration = md.getDurationValue(doc);
String distance = md.getDistanceText(doc);
String start_address = md.getStartAddress(doc);
String copy_right = md.getCopyRights(doc);
ArrayList<LatLng> directionPoint = md.getDirection(doc);
PolylineOptions rectLine = new PolylineOptions().width(3).color(Color.RED);
for(int i = 0 ; i < directionPoint.size() ; i++) {
rectLine.add(directionPoint.get(i));
}
mMap.addPolyline(rectLine);
但我想根据用户的移动动态画线,Google Maps Api V2 是否可行?
谢谢
最佳答案
您可以使用函数 onMyLocationChange 来完成此操作,但您的 Activity 应实现 OnMyLocationChangeListener
@Override
public void onMyLocationChange(Location arg0) {
lastLatLng = currentLatLng ;
currentLatLng = new LatLng(arg0.getLatitude(), arg0.getLongitude());
// here draw again path between those two points
}
现在您有两个新点,一个是用户当前存在的点,另一个是上次位置更新的最后一个点,您必须在不移除旧路径的情况下绘制一条新路径,所以我想这将解决您的问题。
关于android - 使用用户移动在 map Api V2 上绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15675532/