Getting map location Python

*爱你&永不变心* 提交于 2019-12-14 04:26:35

问题


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.


回答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




回答2:


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.



来源:https://stackoverflow.com/questions/17704436/getting-map-location-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!