lyxzxp
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=(需要自己去高德官网获取)"></script>
<script type="text/javascript"> var map = new AMap.Map(\'mapContainer\', { resizeEnable: true }) map.plugin(\'AMap.Geolocation\', function() { var geolocation = new AMap.Geolocation({ // 是否使用高精度定位,默认:true enableHighAccuracy: true, // 设置定位超时时间,默认:无穷大 timeout: 10000, // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20) buttonOffset: new AMap.Pixel(10, 20), // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false zoomToAccuracy: true, // 定位按钮的排放位置, RB表示右下 buttonPosition: \'RB\' }) // 获取当前位置信息 geolocation.getCurrentPosition(); // 监听获取位置信息成功的回调函数 AMap.event.addListener(geolocation, \'complete\', onComplete); // 监听获取位置信息错误的回调函数 AMap.event.addListener(geolocation, \'error\', onError); function onComplete (data) { // data是具体的定位信息 addComp = data.addressComponent; // 获取信息中的省市区并放入到输入框中 $("#fsenderAddress").val(addComp.province+"-"+addComp.city+"-"+addComp.district).trigger("change"); $("#fsenderCountyCode").val(addComp.adcode); let fsenderMsg = { \'fsenderAddress\':$("#fsenderAddress").val(), \'fsenderCountyCode\':$("#fsenderCountyCode").val() } window.sessionStorage.setItem(\'fsendMsg\', JSON.stringify(fsenderMsg)); } function onError (error) { // 定位出错 console.log(error) } }) </script>

 

posted on 2019-07-18 16:09  _Pluto  阅读(5647)  评论(0编辑  收藏  举报

分类:

技术点:

相关文章:

  • 2021-12-22
  • 2021-11-21
  • 2021-12-14
  • 2021-12-22
  • 2022-01-01
  • 2021-08-05
猜你喜欢
  • 2021-12-22
  • 2021-12-10
  • 2021-11-30
  • 2021-12-11
  • 2021-12-14
  • 2021-08-05
相关资源
相似解决方案