3

All!

I need to determine current user City. With HTML5 it's not a problem. But i need support old browsers (leke are ie 7,8). First of all i thought to find location using IP address. But its not easy to implement (i need actual database with location). Free web services not provide me needed info. Many of these can determine a country (but not city).

I tried to use http://www.geoplugin.net/ and this service return only Country (as and another free). I tried to use CSV database with IPs (but in the internet i can find old version).

Do you know free ways to determine user City? Thanks!

2 Answers2

1

Some older browsers do have some support for getting the user location in some form. Back in the IE7/8 days a few different browsers handled geolocation in different ways. This was a pain for developers. I can't for the life of me remember how to do this in IE7/8 but do remember writing a wrapper library for this at some point. Now a days most people use wrapper libraries that handle all the different browser implementations for them. The Bing Maps V7 JavaScript wraps all the old and new functionalities into a common GeoLocationProvider class in their API which might be an option if you need a map in your site: http://msdn.microsoft.com/en-us/library/hh125833.aspx

rbrundritt
  • 16,570
  • 2
  • 21
  • 46
  • Interesting, but it looks like the MS class uses the HTML5 API. In my case I want to be able to detect the country without needing to ask the user's consent. – And Finally Jun 11 '15 at 08:13
  • In that case you need to capture the users IP address and then look up the country from a look up table. There are a bunch of free database out there that have this data. – rbrundritt Jun 11 '15 at 16:54
  • Thanks @rbrundritt.. we're WordPress clients, so we can take advantage of their IP-based geolocation plugin. – And Finally Jun 11 '15 at 22:22
0

You can use our geolocation API https://ip-api.io for this task. It provides data like country, city, zip code

Example request:

$.getJSON("http://ip-api.io/json/",
    function(result) {
        console.log(result);
    });

Example response:

{
  "ip": "64.30.228.118",
  "country_code": "US",
  "country_name": "United States",
  "region_code": "FL",
  "region_name": "Florida",
  "city": "Fort Lauderdale",
  "zip_code": "33309",
  "time_zone": "America/New_York",
  "latitude": 26.1882,
  "longitude": -80.1711,
  "metro_code": 528,
  "suspicious_factors": {
    "is_proxy": false,
    "is_tor_node": false,
    "is_spam": false,
    "is_suspicious": false
  }
}
Andrey E
  • 605
  • 4
  • 8