|
本帖最后由 fan0217 于 2016-11-10 18:30 编辑
这里使用的是腾讯地图。可前往http://map.qq.com/申请开发Key
关键代码:
- ''' <summary>
- ''' 根据经纬度获取地址
- ''' </summary>
- ''' <param name="latitude">纬度</param>
- ''' <param name="longitude">经度</param>
- ''' <param name="tengXunMapKey">腾讯地图开发Key,申请地址http://lbs.qq.com/ </param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Function GetAddress(latitude As Double, longitude As Double, tengXunMapKey As String)
- Dim apiuri As String
- apiuri = "http://apis.map.qq.com/ws/geocoder/v1/?location=" & latitude & "," & longitude & "&key=" & tengXunMapKey
- Dim retJson As String
- retJson = HttpGet(apiuri)
- GetAddress = retJson
- End Function
- Function HttpGet(url As String) As String
- Dim xmlHttp As Object
- Set xmlHttp = CreateObject("Msxml2.XMLHTTP.3.0")
- If Not IsObject(xmlHttp) Then
- Set xmlHttp = CreateObject("Msxml2.XMLHTTP.3.0")
- If Not IsObject(xmlHttp) Then Exit Function
- End If
- xmlHttp.Open "GET", url, False
- xmlHttp.setRequestHeader "CONTENT-TYPE", "application/json;charset=UTF-8"
- xmlHttp.send
- Do While xmlHttp.ReadyState <> 4
- DoEvents
- Loop
-
- Dim ret As String
- ret = xmlHttp.responseText
- HttpGet = ret
- End Function
复制代码
测试:
- Sub Test()
- Debug.Print GetAddress(31.45, 105.75, "O24BZ-GW5RD-V5T4O-HOHGD-MEDWT-DTFB4")
- End Sub
复制代码
输出结果:json格式,自己想办法解析了。
- {
- "status": 0,
- "message": "query ok",
- "request_id": "6202287292262931140",
- "result": {
- "location": {
- "lat": 31.45,
- "lng": 105.75
- },
- "address": "四川省南充市南部县大升路",
- "formatted_addresses": {
- "recommend": "南部县永红乡观音场(大升路西)",
- "rough": "南部县永红乡观音场(大升路西)"
- },
- "address_component": {
- "nation": "中国",
- "province": "四川省",
- "city": "南充市",
- "district": "南部县",
- "street": "大升路",
- "street_number": ""
- },
- "ad_info": {
- "adcode": "511321",
- "name": "中国,四川省,南充市,南部县",
- "location": {
- "lat": 31.450001,
- "lng": 105.75
- },
- "nation": "中国",
- "province": "四川省",
- "city": "南充市",
- "district": "南部县"
- },
- "address_reference": {
- "village": {
- "title": "千佛观村",
- "location": {
- "lat": 31.44953,
- "lng": 105.745461
- },
- "_distance": 434.3,
- "_dir_desc": "东"
- },
- "town": {
- "title": "永红乡",
- "location": {
- "lat": 31.450001,
- "lng": 105.75
- },
- "_distance": 0,
- "_dir_desc": "内"
- },
- "street": {
- "title": "大升路",
- "location": {
- "lat": 31.449713,
- "lng": 105.751801
- },
- "_distance": 167.9,
- "_dir_desc": "西"
- }
- }
- }
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|