获取Android中轻敲地图上的坐标

问题描述:

我正在尝试这样做:我有一个地图,当用户点击地图时,它显示该位置的坐标。我已经超越了onclick的方法,但它甚至不被称为。任何想法?

I'm trying to make something like this: I have a mapactivity and when the user taps the map it shows the coordinates of that location. I already overrided the onclick method but it isn't even called. Any Idea?

public class MapPoint extends MapActivity implements OnClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.mappoints);

    MapView map = (MapView)findViewById(R.id.mapview);
    map.setOnClickListener(this);
    map.setBuiltInZoomControls(true);
    map.getController().setZoom(18);
    map.getController().setCenter(new GeoPoint(39735007, -8827330));


}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

public void onClick(View arg0) {
        Toast.makeText(this, "text", Toast.LENGTH_SHORT);
}

}

请尝试以下操作。

编写一个派生自覆盖类,并覆盖 onTap()方法。然后,您可以将覆盖图添加到您的 MapView 。 A GeoPoint 对象,代表您点击的位置,当您在地图上的某个地方标签时传递给onTap()方法。

Write a class which derives from the Overlay class and override the onTap() method. Then you can add your overlay to the your MapView. A GeoPoint object, which represents the position of you tap, is passed to the onTap() method when you tab somewhere on the map.