geocoder.getFromLocationName returns only null

前端 未结 4 1473
长发绾君心
长发绾君心 2020-12-01 20:01

I am going out of my mind for the last two days with an IllegalArgumentException error I receive in Android code when trying to get a coordinates out of an addr

4条回答
  •  被撕碎了的回忆
    2020-12-01 20:25

    public LatLng determineLatLngFromAddress(Context appContext, String strAddress) {
            LatLng latLng = null;
            Geocoder geocoder = new Geocoder(appContext, Locale.getDefault());
            List
    geoResults = null; try { geoResults = geocoder.getFromLocationName(strAddress, 1); while (geoResults.size()==0) { geoResults = geocoder.getFromLocationName(strAddress, 1); } if (geoResults.size()>0) { Address addr = geoResults.get(0); latLng = new LatLng(addr.getLatitude(),addr.getLongitude()); } } catch (Exception e) { System.out.print(e.getMessage()); } return latLng; //LatLng value of address }

提交回复
热议问题