我如何添加一个标记在地图上的特定位置?
我看到这个code,显示触摸位置的坐标。我想一个标记弹出,或在同一位置每次它被触摸显示。我该怎么做呢?
公共布尔的onTouchEvent(MotionEvent事件,图形页面图形页面){
如果(event.getAction()== 1){
的GeoPoint P = MapView.getProjection()在。fromPixels(
(int)的event.getX(),
(int)的event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6()/ 1E6 +,+
p.getLongitudeE6()/ 1E6,
Toast.LENGTH_SHORT).show();
mapView.invalidate();
}
返回false;
}
解决方案
您要添加的 OverlayItem 。该谷歌MapView类教程展示了如何使用它
How do I add a marker on a particular location in the map?
I saw this code that shows the coordinates of the touched location. And I want a marker to pop or be shown in that same location everytime it is touched. How do I do this?
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
mapView.invalidate();
}
return false;
}
解决方案
You want to add an OverlayItem. The Google Mapview tutorial shows how to use it.