geocoder.getFromLocationName returns only null

前端 未结 4 1467
长发绾君心
长发绾君心 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:08

    I had a similar problem and found that polling the Geocoder until i got a result worked. Here is how i did it, so far works great.

    try {
        List
    geoResults = geocoder.getFromLocationName("
    ", 1); while (geoResults.size()==0) { geoResults = geocoder.getFromLocationName("
    ", 1); } if (geoResults.size()>0) { Address addr = geoResults.get(0); myLocation.setLatitude(addr.getLatitude()); myLocation.setLongitude(addr.getLongitude()); } } catch (Exception e) { System.out.print(e.getMessage()); }

提交回复
热议问题