Reputation: 4490
Is there any way to get the computer geolocation (as in Google Maps "My Location") from a Python script? The computer would always be connected to the Internet.
Upvotes: 0
Views: 4819
Reputation: 114048
>>> import re,requests
>>> raw = requests.get('http://www.geoiptool.com/').text
>>> latlon = re.search("GPoint\(([^)]+)\)",raw).groups(0)
>>> lat,lon = map(float,latlon[0].split(","))
>>> print "Latitude:%s Longitude:%s"%(lat,lon)
Latitude:-117.2455 Longitude:46.7322
a couple of caveats ...
This probably is not the best method and should not be done over and over again or you might upset the site owners
this uses IP lookups so it may not be as good as GPS/wifi coordinates
Upvotes: 3
Reputation: 6162
Google Maps license do not allow using geocoding service API outside map object. Look at this question https://gis.stackexchange.com/questions/18871/is-there-an-open-source-geocoding-tool-which-can-be-used-commercially. Hope it helps.
Upvotes: 0