On many sites I saw printed out my current city where I am (eg "Hello to Berlin."). How they do that? What everything is needed for that? I guess the main part is here javascript, but what everything I need for implementing something like this to my own app? (or is there some gem for Rails?)
Also, I would like to ask for one thing yet - I am interesting in the list of states (usually in select box), where user select his state (let's say Germany), according to the state value are in another select displayed all regions in Germany and after choosing a region are displayed respective cities in the selected region.
Is possible anywhere to obtain this huge database of states/cities/regions? Would be interesting to have something similar in our app, but I don't know, where those lists get...
Internet Service Providers buy up big chunks of IP addresses, so what you're most likely seeing is a backtrace your IP to a known ISP. They have a database with ISP's and their location in the world, so they can try to see where you're from. You could try to use a site like http://www.ipaddresslocation.org/ to do your work. If you look around, there is bound to be a site that lets you enter an IP and get a location, so you just send a POST request to that site with your visitor's IP and scrape the location from the response.
Alternatively you could try to look for an ISP database that has location and what chunks of the IP range they have been allocated. You could probably find one for money, but a free one might be harder to find.Alternatively, check out this free database http://www.maxmind.com/app/geoliteIf you prefer to use ES6 and promises here is another version
And you can use it like this:
Here is an another api to find out the location in PHP,
http://ipinfodb.com/ip_location_api.php
Correc syntax would be :
Use :
I have been using geoip.maxmind.com for quite a while and it works 100%. It can be accessed via HTTP requests.
I've found
getCurrentPosition()
to often be inaccurate since it doesn't spend a lot of time waiting on the GPS to acquire a good accuracy. I wrote a small piece of JavaScript that mimicsgetCurrentPosition()
but actually uses watch position and monitors the results coming back until they are better accuracy.Here's how it looks:
Code is here - https://github.com/gwilson/getAccurateCurrentPosition