Skip to content Skip to sidebar Skip to footer

Getting Map Location Python

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.

Solution 1:

>>> 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 ...

  1. This probably is not the best method and should not be done over and over again or you might upset the site owners

  2. this uses IP lookups so it may not be as good as GPS/wifi coordinates


Solution 2:


Post a Comment for "Getting Map Location Python"