简体   繁体   English

地理编码器,在 Android 中获取国家/地区,getFromLocation 零结果

[英]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.许多确定国家/地区的方法都需要 SIM 卡,但这种方法不需要。 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.例如 lng lat,31.7823555,35.2991956,返回零。

I also tried using a http request to google api, like this我也尝试使用 http 请求到 google api,就像这样

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.如果我理解正确,坐标31.7823555,35.2991956位于西岸。 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 .这是一个已知问题,它在公共问题跟踪器中报告为问题 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.看起来谷歌正在解决这个问题,因为问题的状态是接受,并且有相关的内部问题 #31447205 附加到公共问题。 There is no workaround at the moment for Google Maps API.目前没有适用于 Google Maps API 的解决方法。

I can suggest starring the issue 9792 to express your interest and receive further updates from Google.我可以建议为问题 9792 加注星标以表达您的兴趣并接收来自 Google 的进一步更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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