标签:ntp javascrip plugin marker on() 经纬 lbs 6.4 isp
<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
标签:ntp javascrip plugin marker on() 经纬 lbs 6.4 isp
原文地址:http://www.cnblogs.com/moqiutao/p/7898356.html