zoukankan      html  css  js  c++  java
  • H5百度地图获取定位和地址信息

    下面的BaiduMap就是百度地图的实例对象

          //关于状态码
          const BMAP_STATUS_SUCCESS = 0 //检索成功。对应数值“0”。
          const BMAP_STATUS_CITY_LIST = 1 //城市列表。对应数值“1”。
          const BMAP_STATUS_UNKNOWN_LOCATION = 2 //位置结果未知。对应数值“2”。
          const BMAP_STATUS_UNKNOWN_ROUTE = 3 //导航结果未知。对应数值“3”。
          const BMAP_STATUS_INVALID_KEY = 4 //非法密钥。对应数值“4”。
          const BMAP_STATUS_INVALID_REQUEST = 5 //非法请求。对应数值“5”。
          const BMAP_STATUS_PERMISSION_DENIED = 6 //没有权限。对应数值“6”。(自 1.1 新增)
          const BMAP_STATUS_SERVICE_UNAVAILABLE = 7 //服务不可用。对应数值“7”。(自 1.1 新增)
          const BMAP_STATUS_TIMEOUT = 8 //超时。对应数值“8”。(自 1.1 新增)
          //自动定位
          var geolocation = new BaiduMap.Geolocation();
          geolocation.getCurrentPosition(function(r){
              if(this.getStatus() == BMAP_STATUS_SUCCESS){
                  console.log('您的坐标:' + r.point.lng + ',' + r.point.lat); // 这是百度坐标
                  var lng = r.point.lng;
                  var lat = r.point.lat;
                  // 创建地理编码实例      
                  var myGeo = new BaiduMap.Geocoder();      
                  // 根据坐标得到地址描述    
                  myGeo.getLocation(new BaiduMap.Point(lng, lat), function(result){      
                      if (result){
                        alert('定位成功:'+ result.address);
                      }      
                  });
              }
              else {
                  alert('定位失败:' + this.getStatus());
              }        
          })

    文档:

    【获取定位】https://lbsyun.baidu.com/index.php?title=jspopularGL/guide/geoloaction

    【地址逆解析】https://lbsyun.baidu.com/index.php?title=jspopularGL/guide/geocoding

  • 相关阅读:
    leetcode 18 4Sum
    leetcode 71 Simplify Path
    leetcode 10 Regular Expression Matching
    leetcode 30 Substring with Concatenation of All Words
    leetcode 355 Design Twitte
    leetcode LRU Cache
    leetcode 3Sum
    leetcode Letter Combinations of a Phone Number
    leetcode Remove Nth Node From End of List
    leetcode Valid Parentheses
  • 原文地址:https://www.cnblogs.com/mankii/p/14863577.html
Copyright © 2011-2022 走看看