What Country is the User Currently In?

前端 未结 3 493
春和景丽
春和景丽 2021-01-13 06:56

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 c

相关标签:
3条回答
  • 2021-01-13 07:34

    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

    0 讨论(0)
  • 2021-01-13 07:37

    Try using a web service, like Chris suggested. Here's a list of a few that will do the trick:

    http://free-web-services.com/web-services/geo/ip-to-location/

    I'm using http://www.hostip.info, which is nice and simple.

    0 讨论(0)
  • 2021-01-13 07:57

    What about using an IP-based geolocation service? I would guess that due to regulatory differences network divisions are usually fairly country specific, except in cases such as corporate VPN's where you are virtually plugged into the net somewhere else?

    0 讨论(0)
提交回复
热议问题