標籤: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建立地圖以及擷取當前地址經緯度