我四处张望了一下对计算器和谷歌组和还没有真正找到了这个确切的问题的答案。
我只是希望能够知道的国家的的Android手机用户目前在
我想如果用户只使用WiFi的TelephonyManager不起作用。这是真的吗?
我们已经尝试过使用android.location.Geo codeR用户当前的纬度和经度,但它确实片状。它经常会返回空的结果。有时候,我们可以不断地问它,它最终将返回结果,但它确实难看。有没有更可靠的方式?
谢谢, 罗布SZ
解决方案您可以尝试反向地理编码:)
HTTP://$c$c.google.com/apis/maps/documentation/geocoding/
检查该链接。该国以JSON返回。
http://maps.googleapis.com/maps/api/geo$c$c/json?latlng=40.714224,-73.961452&sensor=false
我真的不知道这是否会适用于所有的情况,但我相信这一点是可以提供帮助。
编辑:像它看起来有点儿工作:)
试着与我的国家,似乎很好地工作。
的http://maps.googleapis.com/maps/api/geo$c$c/json?latlng=6.822716,79.878159&sensor=false
您将获得
{
状态:ZERO_RESULTS
结果:[]
}
例如,如果用户是在海洋通过任何机会,中间:P
I've looked around a bit on stackoverflow and Google Groups and haven't really found an answer for this exact question.
I simply want to be able to know what country the user of an Android phone is currently in.
I assume the TelephonyManager doesn't work if the user is using wifi only. Is this true?
We've tried passing the user's current latitude and longitude using android.location.Geocoder, but it's really flaky. It will frequently return empty results. Sometimes we can keep asking it and it will eventually return results, but it's really ugly. Is there a more reliable way?
Thanks, Rob Sz
解决方案You could try reverse Geo Coding :)
http://code.google.com/apis/maps/documentation/geocoding/
Check this link. The country is returned in JSON.
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
I honestly do not know whether this will work in all scenarios but I believe this is something that can help.
EDIT: Looks like it kinda works :)
Tried with my country and seems to work perfectly.
http://maps.googleapis.com/maps/api/geocode/json?latlng=6.822716,79.878159&sensor=false
You will get
{
"status": "ZERO_RESULTS",
"results": [ ]
}
for example, if the user is in the middle of an ocean by any chance :P
上一篇:仅当依赖项组装到一个 jar 中时才会抛出 Jersey 异常才会、抛出、中时、异常
下一篇:Jersey ContainerRequestFilter 未触发Jersey、ContainerRequestFilter