0

我希望在 android 中实现反向地理编码,但我遇到了一些问题,有人能给我一些指导吗?这是我的代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        textLong = (TextView) findViewById(R.id.textLong);
        textLat = (TextView) findViewById(R.id.textLat);


        LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        LocationListener listener = new myLocationListner();
        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);




    }

    public class myLocationListner implements LocationListener{

        @Override
        public void onLocationChanged(Location location) {
            if (location != null){

                double gettextLong = location.getLongitude();
                double gettextLat = location.getLatitude();

                textLat.setText(Double.toString(gettextLat));
                textLong.setText(Double.toString(gettextLong));


            }
4

1 回答 1

0

您需要创建一个 Geocoder 对象并使用 .getFromLocation 方法:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(gettextLat, getTextLong, 1);

IE:

public class myLocationListner implements LocationListener{

    Geocoder mGeocoder;

    // default constructor
    myLocationListener() {
        // instantiate geocoder object:
        mGeocoder = new Geocoder(this, Locale.getDefault());
    }

    @Override
    public void onLocationChanged(Location location) {
        if (location != null){

            double gettextLong = location.getLongitude();
            double gettextLat = location.getLatitude();

            textLat.setText(Double.toString(gettextLat));
            textLong.setText(Double.toString(gettextLong));

            List<Address> addresses = mGeocoder.getFromLocation(gettextLat, getTextLong, 1);

        }
   }

见:http: //developer.android.com/reference/android/location/Geocoder.html

于 2013-07-18T12:50:58.800 回答