简体   繁体   中英

Geocoder, get country in Android, getFromLocation zero results

I need to get the country the user is in to display certain information, when the user travels abroad. Many methods to determine the country required a sim card, but this way didn't. So this is what i use (with a few try, catchs)

Geocoder myLocation = new Geocoder(HomeActivity.this);
myList = myLocation.getFromLocation(gps.getLatitude(), gps.getLongitude(), 1);
String country = myList.get(0).getCountryName();
Log.d(TAG, country);

Most of the time this is working. However, sometimes the list returns zero results. For example the lng lat, 31.7823555,35.2991956, returns zero.

I also tried using a http request to google api, like this

http://maps.googleapis.com/maps/api/geocode/json?latlng=31.7823555,35.2991956&sensor=true

but it also returned zero.

This should be quite an easy thing to determine, which country the phone is in. Is there a better way. How can I get around this problem of zero results?

Thanks

EDITED

I accept the answer that it's is a disputed area. However, could it also be that if there are no 'landmarks' nearby the latlng point, that there will be zero results? If the point is in the middle of countryside for many kilometers, will there also be zero results?

If I understand correctly the coordinate 31.7823555,35.2991956 is located in West Bank. West Bank is a disputed area at the moment.

Unfortunately, Google Maps reverse geocoding doesn't work in disputed areas. This is a known issue and it was reported in the public issue tracker as issue 9792 . It looks like Google is working on this problem, because the status of the issue is Accepted and there is related internal issue #31447205 attached to public issue. There is no workaround at the moment for Google Maps API.

I can suggest starring the issue 9792 to express your interest and receive further updates from Google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM