继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

关于高德定位封装的api

幸福拾荒者
关注TA
已关注
手记 6
粉丝 8
获赞 190

在开发中项目中通过高德封装的获取经纬度的接口

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>高德定位</title>
</head>
<body>
</body>
</html>
 <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key='开发者秘钥'&plugin=AMap.Geocoder"></script>
<script type="text/javascript">
    window.onload=function(){
    eflower_location.error = function(data){

     }
   //定位初始化
   eflower_location.Gdlocation(function(data){
         alert(data.position.getLng()+" "+data.position.getLat());

    });   
 }
eflower_location={
            success:function(date){},
            error:null,
            GdMapload:function(){
                var Lbody = document.body;
                var LO = document.createElement("div");
                        LO.style.display='none';
                    LO.setAttribute('id', 'ContentMap');
                    Lbody.appendChild(LO);
               },
            Gdlocation:function(_success){
                if(_success != undefined && typeof(_success) == "function"){
                    eflower_location.success=_success;
                }

                eflower_location.GdMapload();
                var lnglatXY=new Array();
                map = new AMap.Map('container');
                map.plugin('AMap.Geolocation', function() {
                    geolocation = new AMap.Geolocation({
                        enableHighAccuracy: true,//是否使用高精度定位,默认:true
                        timeout: 10000,          //超过10秒后停止定位,默认:无穷大
                      });
                    map.addControl(geolocation);
                    geolocation.getCurrentPosition();
                    AMap.event.addListener(geolocation, 'complete',eflower_location.onComplete);//返回定位信息
                    AMap.event.addListener(geolocation, 'error', eflower_location.onError);      //返回定位出错信息
                });
            },
      onComplete:function(data){
        eflower_location.success(data);
          },
          onError:function(data){
                if(eflower_location.error !=null && typeof(eflower_location.error) == "function"){
                    eflower_location.error(data);
                }else{
                        console.error("error");
                        return;
                }
          }
}
</script>
打开App,阅读手记
12人推荐
发表评论
随时随地看视频慕课网APP