zoukankan      html  css  js  c++  java
  • 百度地图api定位,并根据经纬度转换为地址

    方法一

     1 //浏览器定位,并根据定位经纬度转换为地址描述。
     2 var positionOptions = {
     3     enableHighAccuracy: true,
     4     timeout: 3000,
     5     maximumAge: 0
     6 };
     7 var geolocation = new BMap.Geolocation();
     8 geolocation.getCurrentPosition(function(geolocationResult){
     9     if(geolocationResult!=null){
    10         alert(geolocationResult.point.lng)
    11         // alert(geolocationResult.accuracy)
    12         console.log(geolocationResult.point)
    13         var myGeo = new BMap.Geocoder();
    14         // 根据坐标得到地址描述
    15         myGeo.getLocation(new BMap.Point(geolocationResult.point.lng,geolocationResult.point.lat), function(result){
    16             console.log(result.addressComponents)
    17             console.log(result)
    18             console.log(geolocationResult.point)
    19             if (result){
    20                 location = result.address
    21                 alert(location);
    22             }
    23         });
    24     }
    25 }, positionOptions);

    方法二

     1 var geolocation = new BMap.Geolocation();
     2 geolocation.getCurrentPosition(function(r){
     3     if(this.getStatus() == BMAP_STATUS_SUCCESS){
     4         //根据定位经纬度添加标记
     5         var mk = new BMap.Marker(r.point);
     6         map.addOverlay(mk);
     7         console.log(r.point)
     8         map.panTo(r.point);
     9         alert('您的位置:'+r.point.lng+','+r.point.lat);
    10         //根据坐标获取地理位置
    11         map.centerAndZoom(new BMap.Point(r.point.lng,r.point.lat), 10);
    12         // 创建地理编码实例
    13         var myGeo = new BMap.Geocoder();
    14         // 根据坐标得到地址描述
    15         myGeo.getLocation(new BMap.Point(r.point.lng,r.point.lat), function(result){
    16             console.log(result.addressComponents);
    17             console.log(result)
    18             console.log(r.point)
    19             if (result){
    20                 location = result.address
    21                 alert(location);
    22             }
    23         });
    24     }
    25     else {
    26         alert('failed'+this.getStatus());
    27     }
    28 });
  • 相关阅读:
    10个值得我们关注的python博客
    Python获取并修改hosts
    详解python2 和 python3的区别
    Python监控网站运行状况
    用Flask实现视频数据流传输
    Python框架 Flask 项目实战教程
    使用Flask设计带认证token的RESTful API接口[翻译]
    使用python的Flask实现一个RESTful API服务器端[翻译]
    使用单用户模式破解Linux密码
    Linux软件的安装与卸载
  • 原文地址:https://www.cnblogs.com/qing0228/p/14386092.html
Copyright © 2011-2022 走看看