小编ani*_*k25的帖子

Android Geocoder getFromLocationName始终返回null

我一直在尝试对字符串进行地理编码以获取其坐标但我的程序总是崩溃,因为当我尝试使用getFromLocationName()它时返回null.我一直试图解决这个问题几个小时,但没有任何工作.这是我的代码

public class MainActivity extends Activity {

    private GoogleMap mMap;

    List<Address> addresses;
    MarkerOptions miami;
    String myLocation = "Miami,Florida";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (mMap == null) {
            mMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();
        }

        if (mMap != null) {

            Geocoder geocoder = new Geocoder(this);


            double latitude = 0;
            double longitude = 0;

            while(addresses==null){
            try {
                addresses = geocoder.getFromLocationName(myLocation, 1);

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }
            Address address …
Run Code Online (Sandbox Code Playgroud)

java eclipse android android-mapview google-maps-android-api-2

12
推荐指数
1
解决办法
2万
查看次数