zoukankan      html  css  js  c++  java
  • 百度mapapi

     
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>高德地图api展示</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <style>
    html,body,#container{
    height:100%;
    }
    .info{
    26rem;
    }
    </style>
    <body>
    <div id='container'></div>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.10&key=ff0caab6a3718e7c3f997410082a7d98"></script>
    <script type="text/javascript">
    var map = new AMap.Map('container', {
    resizeEnable: true
    });
    AMap.plugin('AMap.Geolocation', function() {
    var geolocation = new AMap.Geolocation({
    enableHighAccuracy: true,//是否使用高精度定位,默认:true
    timeout: 10000, //超过10秒后停止定位,默认:5s
    buttonPosition:'RB', //定位按钮的停靠位置
    buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
    zoomToAccuracy: true, //定位成功后是否自动调整地图视野到定位点

    });
    map.addControl(geolocation);
    geolocation.getCurrentPosition(function(status,result){
    if(status=='complete'){
    onComplete(result)
    }else{
    onError(result)
    }
    });
    });
    //解析定位结果
    function onComplete(data) {
    document.getElementById('status').innerHTML='定位成功'
    var str = [];
    str.push('定位结果:' + data.position);
    str.push('定位类别:' + data.location_type);
    if(data.accuracy){
    str.push('精度:' + data.accuracy + ' 米');
    }//如为IP精确定位结果则没有精度信息
    str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'));
    document.getElementById('result').innerHTML = str.join('<br>');
    }
    //解析定位错误信息
    function onError(data) {
    document.getElementById('status').innerHTML='定位失败'
    document.getElementById('result').innerHTML = '失败原因排查信息:'+data.message;
    }
    </script>
    </body>
    </html>
     
     
    //转自https://www.cnblogs.com/wusifan/p/10054707.html
     
  • 相关阅读:
    自定义asp.net mvc Filter 过滤器
    基于委托的C#异步编程的一个小例子 带有回调函数的例子
    ASCII、Unicode和UTF-8编码的区别
    Specification模式的一个不错的示例代码
    codesmith 自动生成C# model 实体模板
    Quartz.NET 实现定时任务调度
    FtpHelper类匿名获取FTP文件
    crc32 根据字符串获取校验值
    机器学习能做什么
    RunHelper,一个为跑步而设计的开源的android app
  • 原文地址:https://www.cnblogs.com/dedao97/p/10116481.html
Copyright © 2011-2022 走看看