我正在尝试获取用户在谷歌地图上单击的位置(纬度,经度),如何做到这一点?
我试着在网上找到它还没有运气..
关于下面提到的 HelloItemizedOverlay 类,具体实现请参考这个谷歌地图教程。这将在您单击标记的任何位置创建标记,并且还允许用户拖动地图并寻找可以窥视的地方。
class HelloGoogleMaps extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
List<Overlays> mapOverlays = map.getOverlays();
//This is going to be your pointer (you can use whatever image you want as your indicator
final Drawable drawable = this.getResources().getDrawable(R.drawable.indicator);
map.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP)
{
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, HelloGoogleMaps.this);
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(), (int) event.getY());
String lat = Double.toString(p.getLatitudeE6() / (Math.pow(10,6)));
String lon = Double.toString(p.getLongitudeE6() / (Math.pow(10,6)));
OverlayItem overlayitem = new OverlayItem(p, "Title text", "Body Text");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
map.postInvalidate();
return true;
}
}
});
}