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 });
  • 相关阅读:
    贴代码链接
    Full Tank?
    NEERC 2012
    POJ Function Run Fun
    C. Points on Line codeforces 127
    Frequent values
    统计的力量——线段树详细教程
    建筑行业专业咨询公司 _ 捷盟咨询(第一家)
    福建顶点Livebos PK 杭州德昌隆Partin/C,开发平台之间的对决,谁更敏捷?
    寻找 JAVA 控件,彗都控件网\中国控件网(http://www.evget.com)http://www.componentcn.com/
  • 原文地址:https://www.cnblogs.com/qing0228/p/14386092.html
Copyright © 2011-2022 走看看