我想得到地点地址,我尝试:
package com.spot.prototype;
import android.os.Bundle;
import android.view.KeyEvent;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import android.content.Context;
import android.view.MotionEvent;
import android.widget.Toast;
import android.location.Geocoder;
import android.location.Address;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class SpotActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
private LocationManager lm;
private LocationListener locationListener;
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
mapView = ( MapView ) findViewById( R.id.mapView );
mapView.setBuiltInZoomControls( true );
// mapView.setSatellite(true);
// mapView.setStreetView(true);
mc = mapView.getController();
String coordinates[] = { "1.352566007", "103.78921587" };
double lat = Double.parseDouble( coordinates[0] );
double lng = Double.parseDouble( coordinates[1] );
p = new GeoPoint( ( int ) ( lat * 1E6 ), ( int ) ( lng * 1E6 ) );
mc.animateTo( p );
mc.setZoom( 13 );
lm = ( LocationManager ) getSystemService( Context.LOCATION_SERVICE );
locationListener = new MyLocationListener();
lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 200, 10, locationListener );
}
public boolean onKeyDown( int keyCode, KeyEvent event ) {
MapController mc = mapView.getController();
switch( keyCode ) {
case KeyEvent.KEYCODE_3 :
mc.zoomIn();
break;
case KeyEvent.KEYCODE_1 :
mc.zoomOut();
break;
}
return super.onKeyDown( keyCode, event );
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged( Location loc ) {
if ( loc != null ) {
Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault() );
try {
List<Address> addresses = geoCoder.getFromLocation( loc.getLatitude(), loc.getLongitude(), 1 );
System.out.println( loc.getLatitude() );
System.out.println( loc.getLongitude() );
String add = "";
if ( addresses.size() > 0 ) {
for( int i = 0; i < addresses.get( 0 ) .getMaxAddressLineIndex(); ++i ) {
add += addresses.get( 0 ).getAddressLine( i ) + "
";
}
}
Toast.makeText( getBaseContext(), add, Toast.LENGTH_SHORT ) .show();
}
catch( IOException e ) {
e.printStackTrace();
}
}
}
@Override
public void onProviderDisabled( String provider ) {
}
@Override
public void onProviderEnabled( String provider ) {
}
@Override
public void onStatusChanged( String provider, int status, Bundle extras ) {
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
在向我的支持者发出信号时,我看到该地点实际上得到了更新。 但是,地址清单总是null
。 任何人都能够让我了解这一点? 提前感谢。