获取地图位置Python [英] Getting map location Python

查看:86
本文介绍了获取地图位置Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从Python脚本中获取计算机地理位置(如Google Maps中的我的位置)?计算机将始终连接到互联网。

import re,要求
>>> raw = requests.get('http://www.geoiptool.com/').text
>>> latlon = re.search(GPoint \(([^)] +)\),raw).groups(0)
>>> lat,lon = map(float,latlon [0] .split(,))
>>>打印纬度:%s经度:%s%(lat,lon)
纬度:-117.2455经度:46.7322

一些警告......


  1. 这可能不是最好的方法,不应该是一遍又一遍地完成,否则你可能会让网站所有者感到不安。


  2. 这使用IP查找,因此可能不如GPS / wifi坐标那么好。



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.

解决方案

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

这篇关于获取地图位置Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆