您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
geopy是Python关于地理位置的一个第三方库,用这个库来进行地址位置信息的查询和转换非常方便,本文介绍关于geopy的常用的几种用法
pip install geopy
>>> import json, logging
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.geocode("北京天安门")
>>> print location.address
天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国
>>> print (location.latitude, location.longitude)
(39.90733345, 116.391244079988)
>>> print json.dumps(location.raw, indent=4, ensure_ascii=False, encoding='utf8')
{
"display_name": "天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国",
"importance": 0.00025,
"place_id": "74005413",
"lon": "116.391244079988",
"lat": "39.90733345",
"osm_type": "way",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
"osm_id": "25097203",
"boundingbox": [
"39.9072273",
"39.9075343",
"116.3906566",
"116.3918428"
],
"type": "yes",
"class": "building"
}
>>> import json, logging
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.reverse("39.90733345,116.391244079988")
>>> print location.address
天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国
>>> print json.dumps(location.raw, indent=4, ensure_ascii=False, encoding='utf8')
{
"display_name": "天安门, 1, 西长安街, 崇文, 北京市, 东城区, 北京市, 100010, 中国",
"place_id": "74005413",
"lon": "116.391244079988",
"boundingbox": [
"39.9072273",
"39.9075343",
"116.3906566",
"116.3918428"
],
"osm_type": "way",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
"osm_id": "25097203",
"lat": "39.90733345",
"address": {
"building": "天安门",
"city": "北京市",
"house_number": "1",
"country": "中国",
"suburb": "东城区",
"state": "北京市",
"postcode": "100010",
"country_code": "cn",
"road": "西长安街"
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。