浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。

文档全面上新

更科技的视觉体验,更高效的页面结构,快前往体验吧!

体验新版
第1行: 第1行:
{{wxjsapi-sidebar}}<div class="h1-title">地址解析</div><div id="update-time">更新时间:2019年07月03日</div><div class="bluetitle"><div class="services-title-text">简介</div></div><div class="serve-explain-text">通过地址解析,可以将结构化地址(省/市/区/街道/门牌号)解析为对应的经纬度坐标。比如将"北京市海淀区上地十街10号"转化为"116.30051,40.0511"
+
{{wxjsapi-sidebar}}<div class="h1-title">地址解析</div><div id="update-time">更新时间:2019年07月03日</div><div class="bluetitle"><div class="services-title-text">简介</div></div><div class="serve-explain-text">地址解析,简单来讲就是将结构化地址(省/市/区/街道/门牌号)解析为对应的经纬度坐标。比如将"北京市海淀区上地十街10号"转化为"116.30051,40.0511"。当然,地址结构越完整,地址内容越准确,解析的坐标精度也会越高。
地址结构越完整,地址内容越准确,解析的坐标精度也会越高。
+
使用该地址解析服务进行检索,返回的结果包含marker数组数据和完整数据两项。marker数组数据符合小程序marker规范,可以直接用于小程序map中;完整数据包含该服务接口返回的所有详尽的数据,方便开发者进行自定义开发。</div><div class="bluetitle"><div class="services-title-text">实现方法</div></div><div class="devguide"><div class="leftborderbg" style="height:5000px;"></div><div class="devguideorder"><span>1</span>打开快速创建的微信小程序 pages/index/index.js 文件,用下面的代码完全替换原代码</div><div class="devguidecenter">
地址解析服务检索返回的结果包含marker数组数据和完整数据两项。marker数组数据符合小程序marker规范,可以直接用于小程序map中;完整数据包含该服务接口返回的所有详尽的数据,方便开发者进行自定义开发。
+
</div><div class="bluetitle"><div class="services-title-text">实现方法</div></div><div class="devguide"><div class="leftborderbg" style="height:5000px;"></div><div class="devguideorder"><span>1</span>打开快速创建的微信小程序 pages/index/index.js 文件,用下面的代码完全替换原代码</div><div class="devguidecenter">
+
 
在以下的代码中,首先引用百度地图微信小程序JavaScript API 模块,然后在页面的onLoad中声明BMapWX对象,最后调用BMapWX.regeocoding方法进行逆地址解析(从经纬度转换为地址信息)。
 
在以下的代码中,首先引用百度地图微信小程序JavaScript API 模块,然后在页面的onLoad中声明BMapWX对象,最后调用BMapWX.regeocoding方法进行逆地址解析(从经纬度转换为地址信息)。
<pre class="prettyprint codestyle">// 引用百度地图微信小程序JSAPI模块 
+
<pre class="prettyprint codestyle">// 引用百度地图微信小程序JSAPI模块&nbsp;
var bmap = require('../../libs/bmap-wx.js'); 
+
var bmap = require('../../libs/bmap-wx.js');&nbsp;
var wxMarkerData = []; 
+
var wxMarkerData = [];&nbsp;
Page({ 
+
Page({&nbsp;
    data: { 
+
&nbsp; &nbsp; data: {&nbsp;
        markers: [], 
+
&nbsp; &nbsp; &nbsp; &nbsp; markers: [],&nbsp;
        latitude: , 
+
&nbsp; &nbsp; &nbsp; &nbsp; latitude: ,&nbsp;
        longitude: , 
+
&nbsp; &nbsp; &nbsp; &nbsp; longitude: ,&nbsp;
        rgcData: {} 
+
&nbsp; &nbsp; &nbsp; &nbsp; rgcData: {}&nbsp;
    }, 
+
&nbsp; &nbsp; },&nbsp;
    makertap: function(e) { 
+
&nbsp; &nbsp; makertap: function(e) {&nbsp;
        var that = this; 
+
&nbsp; &nbsp; &nbsp; &nbsp; var that = this;&nbsp;
        var id = e.markerId; 
+
&nbsp; &nbsp; &nbsp; &nbsp; var id = e.markerId;&nbsp;
        that.showSearchInfo(wxMarkerData, id); 
+
&nbsp; &nbsp; &nbsp; &nbsp; that.showSearchInfo(wxMarkerData, id);&nbsp;
    }, 
+
&nbsp; &nbsp; },&nbsp;
    onLoad: function() { 
+
&nbsp; &nbsp; onLoad: function() {&nbsp;
        var that = this; 
+
&nbsp; &nbsp; &nbsp; &nbsp; var that = this;&nbsp;
        // 新建百度地图对象 
+
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;// 新建百度地图对象&nbsp;
        var BMap = new bmap.BMapWX({ 
+
&nbsp; &nbsp; &nbsp; &nbsp; var BMap = new bmap.BMapWX({&nbsp;
            ak: '您的ak' 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ak: '您的ak'&nbsp;
        }); 
+
&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;
        var fail = function(data) { 
+
&nbsp; &nbsp; &nbsp; &nbsp; var fail = function(data) {&nbsp;
            console.log(data) 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(data)&nbsp;
        }; 
+
&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp;
        var success = function(data) { 
+
&nbsp; &nbsp; &nbsp; &nbsp; var success = function(data) {&nbsp;
            wxMarkerData = data.wxMarkerData; 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wxMarkerData = data.wxMarkerData;&nbsp;
            that.setData({ 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; that.setData({&nbsp;
                markers: wxMarkerData 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markers: wxMarkerData&nbsp;
            }); 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;
            that.setData({ 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; that.setData({&nbsp;
                latitude: wxMarkerData[0].latitude 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; latitude: wxMarkerData[0].latitude&nbsp;
            }); 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;
            that.setData({ 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; that.setData({&nbsp;
                longitude: wxMarkerData[0].longitude 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; longitude: wxMarkerData[0].longitude&nbsp;
            }); 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;
        } 
+
&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;
        // 发起regeocoding检索请求 
+
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;// 发起regeocoding检索请求&nbsp;
        BMap.regeocoding({ 
+
&nbsp; &nbsp; &nbsp; &nbsp; BMap.regeocoding({&nbsp;
            fail: fail, 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fail: fail,&nbsp;
            success: success, 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: success,&nbsp;
            iconPath: '../../img/marker_red.png', 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iconPath: '../../img/marker_red.png',&nbsp;
            iconTapPath: '../../img/marker_red.png' 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iconTapPath: '../../img/marker_red.png'&nbsp;
        }); 
+
&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;
    }, 
+
&nbsp; &nbsp; },&nbsp;
    showSearchInfo: function(data, i) { 
+
&nbsp; &nbsp; showSearchInfo: function(data, i) {&nbsp;
        var that = this; 
+
&nbsp; &nbsp; &nbsp; &nbsp; var that = this;&nbsp;
        that.setData({ 
+
&nbsp; &nbsp; &nbsp; &nbsp; that.setData({&nbsp;
            rgcData: { 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rgcData: {&nbsp;
                address: '地址:' + data[i].address + '\n', 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; address: '地址:' + data[i].address + '\n',&nbsp;
                desc: '描述:' + data[i].desc + '\n', 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; desc: '描述:' + data[i].desc + '\n',&nbsp;
                business: '商圈:' + data[i].business 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; business: '商圈:' + data[i].business&nbsp;
            } 
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;
        }); 
+
&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;
    } 
+
&nbsp; &nbsp; }&nbsp;
  
 
})
 
})
 
</pre>
 
</pre>
</div><div class="devguideorder"><span>2</span>为能够正常展示地图和检索结果,打开 pages/index/index.wxml 文件,用下面的代码完全替换原代码</div><div class="devguidecenter"><pre class="prettyprint codestyle"><view class="map_container"> 
+
</div><div class="devguideorder"><span>2</span>为能够正常展示地图和检索结果,打开 pages/index/index.wxml 文件,用下面的代码完全替换原代码</div><div class="devguidecenter"><pre class="prettyprint codestyle"><view class="map_container">&nbsp;
  <map class="map" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" show-location="true" markers="{{markers}}" bindmarkertap="makertap"></map> 
+
&nbsp; <map class="map" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" show-location="true" markers="{{markers}}" bindmarkertap="makertap"></map>&nbsp;
</view> 
+
</view>&nbsp;
<view class="rgc_info"> 
+
<view class="rgc_info">&nbsp;
  <text>{{rgcData.address}}</text> 
+
&nbsp; <text>{{rgcData.address}}</text>&nbsp;
  <text>{{rgcData.desc}}</text> 
+
&nbsp; <text>{{rgcData.desc}}</text>&nbsp;
  <text>{{rgcData.business}}</text> 
+
&nbsp; <text>{{rgcData.business}}</text>&nbsp;
 
</view>
 
</view>
 
</pre>
 
</pre>
</div><div class="devguideorder"><span>3</span>拷贝样式代码到 pages/index/index.wxss文件</div><div class="devguidecenter"><pre class="prettyprint codestyle">.map_container{ 
+
</div><div class="devguideorder"><span>3</span>拷贝样式代码到 pages/index/index.wxss文件</div><div class="devguidecenter"><pre class="prettyprint codestyle">.map_container{&nbsp;
    height: 300px; 
+
&nbsp; &nbsp; height: 300px;&nbsp;
    width: 100%; 
+
&nbsp; &nbsp; width: 100%;&nbsp;
} 
+
}&nbsp;
  
.map { 
+
.map {&nbsp;
    height: 100%; 
+
&nbsp; &nbsp; height: 100%;&nbsp;
    width: 100%; 
+
&nbsp; &nbsp; width: 100%;&nbsp;
 
}
 
}
 
</pre>
 
</pre>
</div><div class="devguideorder"><span>4</span>最后保存修改,即可看到示例效果</div><div class="devguidecenter">本示例在页面加载完成后对当前定位点进行了逆地址解析,点击marker可以看到当前地点的相关位置描述信息。
+
</div><div class="devguideorder"><span>4</span>最后保存修改,即可看到示例效果</div><div class="devguidecenter">本示例在页面加载完成后对当前定位点进行了逆地址解析,点击marker可以看到当前地点的相关位置描述信息。</div></div>
 
+
</div></div>
+

2019年7月3日 (三) 15:01的版本

地址解析
更新时间:2019年07月03日
简介
地址解析,简单来讲就是将结构化地址(省/市/区/街道/门牌号)解析为对应的经纬度坐标。比如将"北京市海淀区上地十街10号"转化为"116.30051,40.0511"。当然,地址结构越完整,地址内容越准确,解析的坐标精度也会越高。 使用该地址解析服务进行检索,返回的结果包含marker数组数据和完整数据两项。marker数组数据符合小程序marker规范,可以直接用于小程序map中;完整数据包含该服务接口返回的所有详尽的数据,方便开发者进行自定义开发。
实现方法
1打开快速创建的微信小程序 pages/index/index.js 文件,用下面的代码完全替换原代码

在以下的代码中,首先引用百度地图微信小程序JavaScript API 模块,然后在页面的onLoad中声明BMapWX对象,最后调用BMapWX.regeocoding方法进行逆地址解析(从经纬度转换为地址信息)。

// 引用百度地图微信小程序JSAPI模块 
var bmap = require('../../libs/bmap-wx.js'); 
var wxMarkerData = []; 
Page({ 
    data: { 
        markers: [], 
        latitude: , 
        longitude: , 
        rgcData: {} 
    }, 
    makertap: function(e) { 
        var that = this; 
        var id = e.markerId; 
        that.showSearchInfo(wxMarkerData, id); 
    }, 
    onLoad: function() { 
        var that = this; 
        // 新建百度地图对象 
        var BMap = new bmap.BMapWX({ 
            ak: '您的ak' 
        }); 
        var fail = function(data) { 
            console.log(data) 
        }; 
        var success = function(data) { 
            wxMarkerData = data.wxMarkerData; 
            that.setData({ 
                markers: wxMarkerData 
            }); 
            that.setData({ 
                latitude: wxMarkerData[0].latitude 
            }); 
            that.setData({ 
                longitude: wxMarkerData[0].longitude 
            }); 
        } 
        // 发起regeocoding检索请求 
        BMap.regeocoding({ 
            fail: fail, 
            success: success, 
            iconPath: '../../img/marker_red.png', 
            iconTapPath: '../../img/marker_red.png' 
        }); 
    }, 
    showSearchInfo: function(data, i) { 
        var that = this; 
        that.setData({ 
            rgcData: { 
                address: '地址:' + data[i].address + '\n', 
                desc: '描述:' + data[i].desc + '\n', 
                business: '商圈:' + data[i].business 
            } 
        }); 
    } 

})
2为能够正常展示地图和检索结果,打开 pages/index/index.wxml 文件,用下面的代码完全替换原代码
<view class="map_container"> 
  <map class="map" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" show-location="true" markers="{{markers}}" bindmarkertap="makertap"></map> 
</view> 
<view class="rgc_info"> 
  <text>{{rgcData.address}}</text> 
  <text>{{rgcData.desc}}</text> 
  <text>{{rgcData.business}}</text> 
</view>
3拷贝样式代码到 pages/index/index.wxss文件
.map_container{ 
    height: 300px; 
    width: 100%; 
} 

.map { 
    height: 100%; 
    width: 100%; 
}
4最后保存修改,即可看到示例效果
本示例在页面加载完成后对当前定位点进行了逆地址解析,点击marker可以看到当前地点的相关位置描述信息。
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消