代碼筆記:使用高德地圖API建立地圖以及擷取當前地址經緯度

來源:互聯網
上載者:User

標籤:ntp   javascrip   plugin   marker   on()   經緯   lbs   6.4   isp   

建立API地圖帶有點標記
<script src="http://webapi.amap.com/maps?v=1.4.1&key=bcf87f3263f98cc37309298bca20c622"></script><script type="text/javascript">    // 執行個體化點標記 function addMarker() {        marker = new AMap.Marker({            icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",            position: [116.41, 39.91]        });        marker.setMap(map);    } var map = new AMap.Map(‘container‘, {        resizeEnable: true,        center: [116.40, 39.91],        zoom: 13    }); addMarker();</script>
根據瀏覽器定位擷取當前經緯度
<div id="container_display"></div><script src="https://webapi.amap.com/maps?v=1.4.1&key=bcf87f3263f98cc37309298bca20c622"></script><script>function loadingCurrentPosition(callback){        document.getElementById(‘container_display‘).innerHTML = ‘‘;      //載入地圖,呼叫瀏覽器定位服務    map = new AMap.Map(‘container_display‘, {        resizeEnable: true    });    map.plugin(‘AMap.Geolocation‘, function() {        geolocation = new AMap.Geolocation({            enableHighAccuracy: true,//是否使用高精度定位,預設:true            timeout: 10000,          //超過10秒後停止定位,預設:無窮大            buttonOffset: new AMap.Pixel(10, 20),//定位按鈕與設定的固定位置的位移量,預設:Pixel(10, 20)            zoomToAccuracy: true,      //定位成功後調整地圖視野範圍使定位位置及精度範圍視野內可見,預設:false            buttonPosition:‘RB‘        });        map.addControl(geolocation);        geolocation.getCurrentPosition();        AMap.event.addListener(geolocation, ‘complete‘, onComplete);//返回定位資訊        AMap.event.addListener(geolocation, ‘error‘, onError);      //返回定位出錯資訊    });    //解析定位結果    function onComplete(data) {        var getLngdata = data.position.getLng();        var getLatdata = data.position.getLat();        if(callback){            callback(getLngdata,getLatdata); //回調參數中傳遞經度與緯度        }    }    //解析定位錯誤資訊    function onError(data) {        alert(‘定位失敗‘);    }}$(function(){    var getLng = ‘‘; //存經度    var getLat = ‘‘; //存緯度    //預設載入一次自動擷取當前人的位置    loadingCurrentPosition(function(lngdata,Latdata){        getLng = lngdata;        getLat = Latdata;    });    $(".getCurrentPosition").on(‘click‘,function(){        loadingCurrentPosition(function(lngdata,Latdata){            getLng = lngdata;            getLat = Latdata;        });    });})</script>

高德地圖根據瀏覽器定位擷取當前經緯度API案例地址:http://lbs.amap.com/api/javascript-api/example/location/browser-location
高德開放平台:http://lbs.amap.com/api

代碼筆記:使用高德地圖API建立地圖以及擷取當前地址經緯度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.