哪个国家的用户目前在? [英] What Country is the User Currently In?

查看:139
本文介绍了哪个国家的用户目前在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我四处张望了一下对计算器和谷歌组和还没有真正找到了这个确切的问题的答案。

我只是希望能够知道的国家的的Andr​​oid手机用户目前在

我想如果用户只使用WiFi的TelephonyManager不起作用。这是真的吗?

我们已经尝试过使用android.location.Geo codeR用户当前的纬度和经度,但它确实片状。它经常会返回空的结果。有时候,我们可以不断地问它,它最终将返回结果,但它确实难看。有没有更可靠的方式?

谢谢, 罗布SZ

解决方案

您可以尝试反向地理编码:)

  HTTP://$c$c.google.com/apis/maps/documentation/geocoding/
 

检查该链接。该国以JSON返回。

<$p$p><$c$c>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

这篇关于哪个国家的用户目前在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆