0

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.

2
  • there are api services that can do this that you can talkto using urllib or something Commented Jul 17, 2013 at 15:51
  • That's what I am asking, what are the services that I can use? Or how can I access Google Maps api Commented Jul 17, 2013 at 16:01

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, it worked as I wanted. Thanks as well for the tips.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.