Reputation: 61
I am working on Raspberry PI B+. I have to get the current location of the system in python. Is there a way to do that without using a GPS Module ?
The PI is always connected to the Internet
Upvotes: 0
Views: 1847
Reputation: 21
If you have a Wifi network adaptor connected, you can query Google's geocoding API with the access point data to get location.
The following command line will retrieve the location:
sudo iwlist wlan0 scan | sed -E '1s/.*/{"wifiAccessPoints":[/;s/^ *Cell.*: (.*)/{"macAddress":"\1",/;s/^ *Channel:(.*)/"channel":\1,/;s/^.*nal level=(-[0-9]+) .*/"signalStrength":\1},/;/^ /d;$d' | sed '$s/.$/]}/' | curl -d @- -H "Content-Type: application/json" "https://www.googleapis.com/geolocation/v1/geolocate?key=${APIKEY}"
You'll need to set the APIKEY
environment variable. You can get an API key from https://developers.google.com/maps/documentation/geocoding/get-api-key.
Upvotes: 0
Reputation: 969
I don't know the application, but this is close enough to freak me out.
html5_geolocation_watchposition
Click the button to Try it; Share you location with w3schools.com; Modify the script in the other panel of the webpage to suit.
Edit: Sorry, just noticed the "in Python" but will leave it up.
Upvotes: -1
Reputation:
Take a look at the GeoIP2. It won't work like a GPS but depending on the purpose, might be useful.
Upvotes: 0