I know that Android has a way to get location, and W3C has a location API for web browsers, but is there a way to get my location progromatically on my own machine?
I'm running Ubuntu 14.10
Edit: Removed ruby tag. Opening up to any language.
I know that Android has a way to get location, and W3C has a location API for web browsers, but is there a way to get my location progromatically on my own machine?
I'm running Ubuntu 14.10
Edit: Removed ruby tag. Opening up to any language.
Short answer for your question: with just Ruby - you can't decode your location
when working on localhost.
You might try using gem trifle for that, but what it does is a GeoIP country lookup. Because you want to try to decode your localhost
- it can't just work.
How it works is - it has a database of IP's and associated cities. This will work when you deploy the application, and it will try to decode your visitor's locations.
Example in their github is quite easy. Once your trifle
gem is set up properly (it requires redis server, and loading provided file with predefined IP's and associated cities):
trifle = Trifle.new(Redis.new)
trifle.find "223.255.128.0"
# => ["HK", "Hong Kong"]
# or you can try to play with it in controller
trifle.find request.remote_ip
What you can do, to decode your location when working in locahost
:
There is a way to obtain location of computer accessing your application using browser's capabilities. There is a great article in tutsplus - http://code.tutsplus.com/tutorials/an-introduction-to-the-geolocation-api--cms-20071. This will work with localhost
There is quite long code presented, so I wont copy it here, but explanation is very good. You can easily implement your solution based on the article, and the location is very accurate. The limitation for this is - browser asks if it can obtain location of computer, and user might not allow that operation. There is no way for forcing it.
Hope that helps!
Good luck!