admin 管理员组文章数量: 887021
项目用到正逆地址解析,记录一下以便再次使用,接口可用于异步GET请求,script方式,h5页面,小程序,手机,同时可用于后端服务。
1.百度
逆地址解析(根据经纬度获取中文地址)
百度文档 - 逆地址解析
接口:http://api.map.baidu/geocoder/v2/callback=renderReverse&location=35.658651,139.745415&output=json&pois=1
请求方式:GET
//GET请求
<script src="http://api.map.baidu/geocoder/v2/?callback=renderReverse&location=35.658651,139.745415&output=json&pois=1&ak=您的ak"></script>
<script type="text/javascript">
function renderReverse(res) {
console.log(res);
// 返回数据
var res = {
status: 0,
result: {
location: {
lng: 139.7454149999999,
lat: 35.658650898203035
},
formatted_address: "東京都港区芝公園4-2-8, Minato, Tokyo, Japan",
business: "",
addressComponent: {
country: "Japan",
country_code: 26000,
country_code_iso: "JPN",
country_code_iso2: "JP",
province: "Tokyo",
city: "Minato",
city_level: 1,
district: "",
town: "",
adcode: "0",
street: "東京都港区芝公園4-2-8",
street_number: "",
direction: "附近",
distance: "40"
},
pois: [ ],
roads: [ ],
poiRegions: [ ],
sematic_description: "",
cityCode: 26041
}
}
}
</script>
正地址解析(根据中文地址获取经纬度)
百度文档 - 正地址解析
接口:http://api.map.baidu/geocoder/v2/?address=北京市海淀区上地十街10号&output=json&ak=您的ak
请求方式:GET
//GET请求
<script src="http://api.map.baidu/geocoder/v2/?address=北京市海淀区上地十街10号&output=json&ak=您的ak&callback=showLocation"></script>
<script type="text/javascript">
function showLocation(res) {
console.log(res);
// 返回数据
var res = {
status: 0,
result: {
location: {
lng: 116.3084202915042,
lat: 40.05703033345938
},
precise: 1,
confidence: 80,
comprehension: 100,
level: "道路"
}
}
}
</script>
2.腾讯地图
逆地址解析(根据经纬度获取中文地址)
腾讯文档 - 逆地址解析
接口:https://apis.map.qq/ws/geocoder/v1/callback=renderReverse&location=39.984154,116.307490&get_poi=0
请求方式:GET
//GET请求
<script src="https://apis.map.qq/ws/geocoder/v1/callback=renderReverse&location=39.984154,116.307490&get_poi=0&key=您的key"></script>
<script type="text/javascript">
function renderReverse(res) {
console.log(res);
// 返回数据
var res = {
status: 0,
message: "query ok",
request_id: "a65b2700-f79f-11e8-9b79-6c92bf53528b",
result: {
location: {
lat: 39.984154,
lng: 116.30749
},
address: "北京市海淀区北四环西路66号",
formatted_addresses: {
recommend: "海淀区中关村中国技术交易大厦",
rough: "海淀区中关村中国技术交易大厦"
},
address_component: {
nation: "中国",
province: "北京市",
city: "北京市",
district: "海淀区",
street: "北四环西路",
street_number: "北四环西路66号"
},
ad_info: {
nation_code: "156",
adcode: "110108",
city_code: "156110000",
name: "中国,北京市,北京市,海淀区",
location: {
lat: 39.984154,
lng: 116.307487
},
nation: "中国",
province: "北京市",
city: "北京市",
district: "海淀区"
}
}
</script>
正地址解析(根据中文地址获取经纬度)
腾讯文档 - 正地址解析
//GET请求
<script src="https://apis.map.qq/ws/geocoder/v1/?address=北京市海淀区彩和坊路海淀西大街74号&key=您的key&callback=showLocation"></script>
<script type="text/javascript">
function showLocation(res) {
console.log(res);
// 返回数据
var res = {
status: 0,
message: "query ok",
result: {
title: "海淀西大街74号",
location: {
lng: 116.30676,
lat: 39.98296
},
address_components: {
province: "北京市",
city: "北京市",
district: "海淀区",
street: "海淀西大街",
street_number: "74"
},
similarity: 0.8,
deviation: 1000,
reliability: 7,
level: 9
}
}
}
</script>
本文标签: 腾讯 地址 地图 javascript
版权声明:本文标题:百度、腾讯地图正逆地址解析 javascript 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1726782314h1027883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论