例如,如果您使用畫布在您的mapview上繪製線條,那麼您需要獲取x,y點的起點和終點。
然後通過以下代碼,您可以將x,y點更改爲經度和緯度。
public boolean onTouchEvent(MotionEvent event)
{
int X = (int)event.getX();
int Y = (int)event.getY();
GeoPoint geoPoint = mapView.getProjection().fromPixels(X, Y);
}
然後在你的mapvierw像這樣重新監聽listener。
map.setOnCameraChangeListener(new OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition arg0) {
// Move camera.
Here remove your view from screen and then get lat long of visible region by passing x,y points of 4 regions in `mapView.getProjection().fromPixels(x,y)` and then check if latitude and longitude of your line within range if yes then drawline by following code.
float pisteX;
float pisteY;
Projection projection = this.mapView.getProjection();
Point pt = new Point();
GeoPoint gie = new GeoPoint(latitude,longitude);
Rect rec = mapView.getScreenRect(new Rect());
projection.toPixels(gie, pt);
pisteX = pt.x-rec.left; // car X screen coord
pisteY = pt.y-rec.top; // car Y screen coord
Now draw line between this two (x,y) points.
}
});
希望我可以讓你清楚,你可以理解我想說什麼。
我發現溶液[這裏] [1]這是通過在標記拖動事件 [1]使用折線:http://stackoverflow.com/questions/18297392/draw-polygon-using- onmarkerdrag-google-map-v2 – Eman87