zoukankan      html  css  js  c++  java
  • HBuilder中使用百度地图定位功能

    定位功能有两种方法:

    首先要初始化内置地图:

    var map =new BMap.Map("map");

    在html中需要定义好id

    <div id="map"></div>

    1、调用GPS定位API(注意,使用了baidu和bd09ll参数,无需转换坐标)

    mui.plusReady(function() {//表示页面加载事件
    plus.geolocation.getCurrentPosition(function(p) {
              console.log(p.addresses);
              console.log( p.coords.longitude);
              console.log( p.coords.latitude);
              var gpsPoint = new BMap.Point( p.coords.longitude,  p.coords.latitude);
              map.centerAndZoom(gpsPoint, 19); 
          }, function(e) {}, {
              provider: 'baidu',
            coordsType: 'bd09ll'
        });
    })

    2、使用h5+内置地图进行定位

    map.getUserLocation(function(state, pos) {
        console.log(JSON.stringify(pos));
        if(0 == state) {
            map.centerAndZoom(pos, 16);
            plus.maps.Map.reverseGeocode(pos, {}, function(event) {
                var address = event.address; // 转换后的地理位置
                var point = event.coord; // 转换后的坐标信息
                var coordType = event.coordType; // 转换后的坐标系类型
                alert("Address:" + address);
                console.log(JSON.stringify(point));
                console.log(coordType);
            }, function(e) {
                alert("Failed:" + JSON.stringify(e));
            });
        }
    });

     

  • 相关阅读:
    学习 swift (1)
    Sbulime Text 2 修改选中字符串的颜色
    js string 和 json 互转
    Mac OSX sublime text2 各种快捷键
    webstorm keymap
    python http post json
    node.js async 几个函数
    python 爬图 helloworld
    合服导致 globalserver 起不来的问题
    ssh 登陆 端口转发
  • 原文地址:https://www.cnblogs.com/ZHANG576433951/p/12601334.html
Copyright © 2011-2022 走看看