反向地理编码未显示地址

时间:2015-01-15 15:56:13

标签: android geocoding reverse-geocoding

此代码显示无法获取地址。 是否有可能从纬度和经度获取地址? 会是什么原因?

我一直在尝试许多类似的代码,但我无法做到。我也试过以下网站解决方案。但没什么用的。

http://javapapers.com/android/android-location-using-gps-network-provider/

http://karanbalkar.com/2013/11/tutorial-63-implement-reverse-geocoding-in-android/

代码在这里

package com.example.androidreversegeocode;``

import java.io.IOException;   
import java.util.List;  
import java.util.Locale;  
import android.location.Address;    
import android.location.Geocoder;  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.View;  
import android.widget.Button;    
import android.widget.TextView;  
import android.widget.Toast;
public class MainActivity extends Activity {

private Button myLocation;
private TextView myAddress;

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

    myLocation= (Button) findViewById(R.id.location);
    myAddress = (TextView)findViewById(R.id.address);

    myLocation.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            getMyLocationAddress();
        }
    });

}

public void getMyLocationAddress() {

    Geocoder geocoder= new Geocoder(this, Locale.ENGLISH);

    try {

          //Place your latitude and longitude
          List<Address> addresses = geocoder.getFromLocation(13.05612948,80.27297011, 1);

          if(addresses != null) {

              Address fetchedAddress = addresses.get(0);
              StringBuilder strAddress = new StringBuilder();

              for(int i=0; i<fetchedAddress.getMaxAddressLineIndex(); i++) {
                    strAddress.append(fetchedAddress.getAddressLine(i)).append("\n");
              }

              myAddress.setText("I am at: " +strAddress.toString());

          }

          else
              myAddress.setText("No location found..!");

    } 
    catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
             Toast.makeText(getApplicationContext(),"Could not get address..!", Toast.LENGTH_LONG).show();
    }
}

}

0 个答案:

没有答案
相关问题