单击位置图标时如何获取地址信息

时间:2013-06-26 11:44:52

标签: android android-mapview android-maps android-event

我的应用中设置了一个位置代码。我想点击位置图标时获取地址信息。如何使用点击事件

public class MyActivity extends MapActivity implements LocationListener 
{

MapView mapView;
MapController mc;
private MyLocationOverlay myLocOverlay;
private String provider;
private LocationManager lm;
Drawable location = null;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.location);

    mapView = (MapView) findViewById(R.id.mview);
    mc = mapView.getController();
    mapView.setBuiltInZoomControls(true);
    mc.setZoom(15);

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    provider = lm.getBestProvider(criteria, false);

    Location location = lm.getLastKnownLocation(provider);

    if(location != null){
        onLocationChanged(location);
    }
}

@Override
protected void onResume(){
    super.onResume();               
    lm.requestLocationUpdates(provider, 400, 1, this);
    myLocOverlay = new MyLocationOverlay(location.this, mapView);
    myLocOverlay.enableMyLocation();
    mapView.getOverlays().add(myLocOverlay);
    myLocOverlay.runOnFirstFix(new Runnable() {

        @Override
        public void run() {
            mc.animateTo(myLocOverlay.getMyLocation());

        }
    });

     mapView.postInvalidate();
}

@Override   
protected void onPause() {    
    super.onPause();
    lm.removeUpdates(this); 
    myLocOverlay.disableMyLocation();
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
@Override
public void onLocationChanged(Location location) {

    double lat = location.getLatitude();
    double lng = location.getLongitude();

}
@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}
@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

 }

0 个答案:

没有答案