MUI框架---实现百度地图定位功能

1
2
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=HR3RRyTsXYdQ3QzzG5yUkg0q"></script>
    <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>

    这个是MUI封装好的JS,可用来调用移动设备底层功能:

1
<script src="../js/mui.min.js"></script>

    HTML代码:

 

1
2
3
<div id="allmap">
    地图加载中...
</div>

    JS调用底层:

1
2
3
4
5
mui.plusReady(function(){
    plus.geolocation.getCurrentPosition(translatePoint,function(e){
        mui.toast("异常:" + e.message);
    });
});

    最核心的部分,创建地图并且转换坐标:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function translatePoint(position){
    var currentLon = position.coords.longitude;
    var currentLat = position.coords.latitude;
    var gpsPoint = new BMap.Point(currentLon,currentLat);
    BMap.Convertor.translate(gpsPoint,2,initMap); //坐标转换
}
function initMap(point){
    map = new BMap.Map("allmap"); //创建地图
    map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.ScaleControl());
    map.addControl(new BMap.OverviewMapControl());
    map.centerAndZoom(point,15);
    map.addOverlay(new BMap.Marker(point));
 
 
posted @ 2016-12-13 01:09  走小天  阅读(7271)  评论(2编辑  收藏  举报