Any Reliable API available to determine User's

2019-01-30 12:22发布

Heyy guys

I wanted to check if anyone knows of a reliable API that we can use to determine the user's city and country from his IP address.

My search on Google led to http://ipinfodb.com/ip_location_api.php

It seems perfect but my only concern is the reliability of this service. Does google have anything like this. If you know any other Free or paid API's that help determine user's location from his IP - please let me know

THanks

7条回答
放我归山
2楼-- · 2019-01-30 12:45

MaxMind has a lite version of their ip2country and ip2city databases: http://www.maxmind.com/app/geolitecity

http://www.maxmind.com/app/geolitecountry

If you don't mind hosting the database yourself, it's free. The paid services are more accurate.

They also provide web services for querying, but it is not free: http://www.maxmind.com/app/web_services#country

查看更多
三岁会撩人
3楼-- · 2019-01-30 12:48

Consider using geoplugin, it provides the most information from a single line PHP code, but requires a connection to the geoplugin.com server for every request (and it is free).

Examples :

Json : http://www.geoplugin.net/json.gp?ip=74.125.236.174

{
geoplugin_request: "74.125.236.174",
geoplugin_status: 200,
geoplugin_city: "Mountain View",
geoplugin_region: "CA",
geoplugin_areaCode: "650",
geoplugin_dmaCode: "807",
geoplugin_countryCode: "US",
geoplugin_countryName: "United States",
geoplugin_continentCode: "NA",
geoplugin_latitude: "37.419201",
geoplugin_longitude: "-122.057404",
geoplugin_regionCode: "CA",
geoplugin_regionName: "California",
geoplugin_currencyCode: "USD",
geoplugin_currencySymbol: "$",
geoplugin_currencySymbol_UTF8: "$",
geoplugin_currencyConverter: 1
}

Xml : http://www.geoplugin.net/xml.gp?ip=74.125.236.174

<geoPlugin>
<script/>
<geoplugin_request>74.125.236.174</geoplugin_request>
<geoplugin_status>200</geoplugin_status>
<geoplugin_city>Mountain View</geoplugin_city>
<geoplugin_region>CA</geoplugin_region>
<geoplugin_areaCode>650</geoplugin_areaCode>
<geoplugin_dmaCode>807</geoplugin_dmaCode>
<geoplugin_countryCode>US</geoplugin_countryCode>
<geoplugin_countryName>United States</geoplugin_countryName>
<geoplugin_continentCode>NA</geoplugin_continentCode>
<geoplugin_latitude>37.419201</geoplugin_latitude>
<geoplugin_longitude>-122.057404</geoplugin_longitude>
<geoplugin_regionCode>CA</geoplugin_regionCode>
<geoplugin_regionName>California</geoplugin_regionName>
<geoplugin_currencyCode>USD</geoplugin_currencyCode>
<geoplugin_currencySymbol>&#36;</geoplugin_currencySymbol>
<geoplugin_currencySymbol_UTF8>$</geoplugin_currencySymbol_UTF8>
<geoplugin_currencyConverter>1</geoplugin_currencyConverter>
</geoPlugin>

Other options

查看更多
SAY GOODBYE
4楼-- · 2019-01-30 12:53

In a sense, you can't reliably know the location of a user. Using the tips the other answers provide will give you the geolocation of an IP, but there's no way to know that that IP address in New York USA isn't being accessed through a VPN from someone on a business trip to London, UK, or whether someone's using an anonymizing service like Tor.

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-30 12:59

Every IP geolocation depends on records submitted by the ISP. This will never be completely reliable because many ISPs submit location of their office instead of physical locations of their subnets which may be in a different city or even country.

查看更多
劫难
7楼-- · 2019-01-30 13:03

Does google have anything like this.

No, Google does not provide a service similar to this. (note that the answer here which claims that it does provide it, leads to nowhere).

Any other Free or paid API's that help determine user's location from his IP

First of all it is hard to speak about reliability of such service. Most of the services rely on ISP to get their data and ISP not always provide reliable data. Moreover because I assume that you basically cares about the location of your user (and not what location his IP belongs), the user can decide to hide his location either through VPN, Tor or other anonymisers.

In some of your comments, I have seen that by reliable you means uptime of the API provider. If so, than I would recommend MaxMind's GeoIP2. First of all, I have seen this site for long time, they are updated pretty often (last update 1-st April 2014), moreover if you are so afraid of downtime - you can download their database and do not rely on them (also they are free).

Another service I actually like is less known and opensource (it partially relies on data from MaxMind). I have used it only a few times, so I can not say about it's uptime, but I really like theirs API. It is so simple, that it is hard to come up with simpler:

http://www.telize.com/geoip/46.19.37.108 

or like this

http://www.telize.com/geoip/2a02:2770::21a:4aff:feb3:2ee

will give you

{
"country":"Netherlands",
"dma_code":"0",
"timezone":"Europe\/Amsterdam",
"area_code":"0",
"ip":"46.19.37.108",
"asn":"AS196752",
"continent_code":"EU",
"isp":"Tilaa V.O.F.",
"longitude":5.75,
"latitude":52.5,
"country_code":"NL",
"country_code3":"NLD"
}

I think that these two services are pretty enough to get normal information for your visitors. But one important thing. If you really need to know where you users came from - why not to ask them with html5 geolocation? Here is a nice example, but you can go further (ask them if the location is correct and give them ability to change it). I know that in your case you need only Country/City, but may be other people will need it.


P.S. Nov 2015. Now that telize.com costs money to use, I found another service that is currently free:

https://freegeoip.net/json/45.79.8.237
https://freegeoip.net/json/2600:3c00::f03c:91ff:fe98:c0f5
查看更多
登录 后发表回答