日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用hbuilder的maps模块调起百度地图导航

發布時間:2024/9/27 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用hbuilder的maps模块调起百度地图导航 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先需要在百度地圖開放平臺,創建應用拿到appid,然后在hbuilder進行如下配置:



hbuilder的manifest.json的配置如下:

permissions下添加如下代碼:

"Maps": {"description": "地圖"}

然后引入百度地圖的js:

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak='這里是訪問應用的ak'"></script>

根據傳入的起始位置和終點位置進行導航

$.ajax({ type: "GET",timeout:50000, url: 'http://api.map.baidu.com/geocoder/v2/?address='+terminal+'&output=json&coord_type=wgs84&ak=31hswa0Y8ZprG7ztIFTAuPon5x4pqBb3&callback=showLocation',dataType:"jsonp",async: false, success: function(data){console.log(JSON.stringify(data));var lat = data['result']['location']['lat'];var lng = data['result']['location']['lng'];$.ajax({ type: "GET",timeout:50000, url: 'http://api.map.baidu.com/geocoder/v2/?location='+lat+','+lng+'&output=json&coord_type=wgs84&ak=31hswa0Y8ZprG7ztIFTAuPon5x4pqBb3&callback=showLocation',dataType:"jsonp",async: false, success: function(data){// console.dir(data['result']['addressComponent']['city']);city = data['result']['addressComponent']['city'];// alert(city);if(terminal != ''){var geolocation = new BMap.Geolocation();var gc = new BMap.Geocoder(); geolocation.getCurrentPosition(function(r){if(this.getStatus() == BMAP_STATUS_SUCCESS){// alert('您的位置:'+r.point.lng+','+r.point.lat);var pt = r.point; gc.getLocation(pt, function(rs){ var addComp = rs.addressComponents; // location.href = 'http://api.map.baidu.com/direction?origin=latlng:'+r.point.lat+','+r.point.lng+'|name:我的位置&destination=latlng:'+lat+','+lng+'|name:'+terminal+'&mode=driving&origin_region='+addComp.city+'&destination_region='+city+'&output=html&src=yourCompanyName|yourAppName';function plusReady(){// 設置目標位置坐標點和起始位置坐標點var src = new plus.maps.Point(r.point.lng,r.point.lat); // 起始位置 var dst = new plus.maps.Point(lng,lat); //// 調用系統地圖顯示 plus.maps.openSysMap( dst, terminal, src );}if(window.plus){plusReady();}else{document.addEventListener("plusready",plusReady,false);}}); }else {alert('failed'+this.getStatus());} },{enableHighAccuracy: true})}},error:function(){alert("網絡異常");}});},error:function(){alert("網絡異常");}});

備注:不是很了解maps模塊的可以去html5+Dcloud:
(http://www.dcloud.io/runtime.html)

總結

以上是生活随笔為你收集整理的使用hbuilder的maps模块调起百度地图导航的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。