高德AMAP行政区划边界及经纬度获取

合集下载

使用高德地图,利用搜索功能,获取地址详情、经纬度等信息

使用高德地图,利用搜索功能,获取地址详情、经纬度等信息

使⽤⾼德地图,利⽤搜索功能,获取地址详情、经纬度等信息效果展⽰需求:1、实现⾼德地图输⼊地址⾃动提⽰功能 ,根据筛选结果,默认显⽰第⼀个结果2、实现单击获取某个地点的经纬度和地址信息3、实现筛选地址标注点4、实现地图回显,再次打开地图定位到之前选中的地址展⽰详情5、封装地图组件可在项⽬中任意地⽅使⽤注意点:⾸先项⽬中需要引⽤⾼德地图,并且我同步引⽤了⾼德的PlaceSearch、AdvancedInfoWindow、Autocomplete这⼏个插件,⾼德提供同步引⽤和异步引⽤,异步引⽤的话,需要你⾃⼰去⾼德的⽂档看看<script src="https:///maps?v=1.4.15&key=换成你⾃⼰的key&plugin=AMap.PlaceSearch,AMap.AdvancedInfoWindow,AMap.Autocomplete"></script>⾸先发⼀份可直接打开看的vue⽂件<template><basic-container><el-button @click="openMap">打开地图选择</el-button><el-dialogtitle="地图选择":visible.sync="mapDialog"width="80%":close-on-click-modal="false":before-close="cancelMap"top="10vh"><div class="over-hide"><div id="myPageTop"><table><tr><td></td></tr><tr><td><el-inputplaceholder="请输⼊关键字进⾏查询"v-model="inputAddress"id="tipinput"@clear="inputHandle"@input="clickCancle"clearable></el-input></td></tr></table></div><div id="container" class="map"></div><br /><br /></div><span slot="footer" class="dialog-footer"><div class="t-a-l"><el-row class="infoAddressIpt"><el-col :span="2"><span>详细地址</span></el-col><el-col :span="22"><el-input v-model="saveAddress"></el-input></el-col></el-row><span class="spb">重要提醒:地址标准格式**市**区**路**号。

高德地图JSAPI获取经纬度,根据经纬度获取城市

高德地图JSAPI获取经纬度,根据经纬度获取城市

⾼德地图JSAPI获取经纬度,根据经纬度获取城市<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>输⼊提⽰后查询,点击获取坐标</title><style type="text/css">#mapContainer{position: absolute;top:0;left: 0;right:0;bottom:0;}#tip{background-color:#fff;border:1px solid #ccc;padding-left:10px;padding-right:2px;position:absolute;min-height:65px;top:10px;font-size:12px;right:10px;border-radius:3px;overflow:hidden;line-height:20px;min-width:30%;}#tip input[type="button"]{background-color: #0D9BF2;height:25px;text-align:center;line-height:25px;color:#fff;font-size:12px;border-radius:3px;outline: none;border:0;cursor:pointer;}#tip input[type="text"]{height:25px;border:1px solid #ccc;padding-left:5px;border-radius:3px;outline:none;}#pos{height: 110px;background-color: #fff;padding-left: 10px;padding-right: 10px;position:absolute;font-size: 12px;right: 10px;bottom: 30px;border-radius: 3px;line-height: 30px;border:1px solid #ccc;}#pos input{border:1px solid #ddd;height:23px;border-radius:3px;outline:none;width: 100px;}#result1{max-height:300px;}b{display: block;margin: 5px 0;}</style></head><body><div style="width: 500px;height: 500px;position: relative;"><div id="mapContainer"></div><div id="tip"><b>请输⼊关键字:</b><input type="text" id="keyword" name="keyword" value="" onkeydown='keydown(event)' style="width: 95%;"/><div id="result1" name="result1"></div></div><div id="pos"><b>⿏标左键在地图上单击获取坐标</b><div>X:<input type="text" id="lngX" name="lngX" value=""/> Y:<input type="text" id="latY" name="latY" value=""/></div><div>城市:<input type="text" id="city" name="city" value=""/></div></div></div><!--请把js引⼊部分的key值换成你申请下来的,要不然不能⽤哦~~--><script type="text/javascript" src="/maps?v=1.3&key=84a1f826e2e135184370cddc9e7848acluo"></script><script type="text/javascript">var windowsArr = [];var marker = [];var mapObj = new AMap.Map("mapContainer", {resizeEnable: true,view: new AMap.View2D({resizeEnable: true,zoom:13//地图显⽰的缩放级别}),keyboardEnable:false});var clickEventListener=AMap.event.addListener(mapObj,'click',function(e){console.log(e);document.getElementById("lngX").value=e.lnglat.getLng();document.getElementById("latY").value=e.lnglat.getLat();AMap.service('AMap.Geocoder',function(){//回调函数//实例化Geocodergeocoder = new AMap.Geocoder({city: ""//城市,默认:“全国”});var lnglatXY=[e.lnglat.getLng(), e.lnglat.getLat()];//地图上所标点的坐标geocoder.getAddress(lnglatXY, function(status, result) {if (status === 'complete' && === 'OK') {//获得了有效的地址信息://即,result.regeocode.formattedAddress//console.log(result);var city = result.regeocode.addressComponent.city;}else{var city = '获取失败';//获取地址失败}document.getElementById("city").value=city;console.log(city);});})});document.getElementById("keyword").onkeyup = keydown;//输⼊提⽰function autoSearch() {var keywords = document.getElementById("keyword").value;var auto;//加载输⼊提⽰插件AMap.service(["AMap.Autocomplete"], function() {var autoOptions = {city: "" //城市,默认全国};auto = new AMap.Autocomplete(autoOptions);//查询成功时返回查询结果if ( keywords.length > 0) {auto.search(keywords, function(status, result){autocomplete_CallBack(result);});}else {document.getElementById("result1").style.display = "none";}});}//输出输⼊提⽰结果的回调函数function autocomplete_CallBack(data) {var resultStr = "";var tipArr = data.tips;if (tipArr&&tipArr.length>0) {for (var i = 0; i < tipArr.length; i++) {resultStr += "<div id='divid" + (i + 1) + "' onmouseover='openMarkerTipById(" + (i + 1)+ ",this)' onclick='selectResult(" + i + ")' onmouseout='onmouseout_MarkerStyle(" + (i + 1)+ ",this)' style=\"font-size: 13px;cursor:pointer;padding:5px 5px 5px 5px;\"" + "data=" + tipArr[i].adcode + ">" + tipArr[i].name + "<span style='color:#C1C1C1;'>"+ tipArr[i].district + "</span></div>";}}else {resultStr = " π__π亲,⼈家找不到结果!<br />要不试试:<br />1.请确保所有字词拼写正确<br />2.尝试不同的关键字<br />3.尝试更宽泛的关键字";}document.getElementById("result1").curSelect = -1;document.getElementById("result1").tipArr = tipArr;document.getElementById("result1").innerHTML = resultStr;document.getElementById("result1").style.display = "block";}//输⼊提⽰框⿏标滑过时的样式function openMarkerTipById(pointid, thiss) { //根据id打开搜索结果点tipthiss.style.background = '#CAE1FF';}//输⼊提⽰框⿏标移出时的样式function onmouseout_MarkerStyle(pointid, thiss) { //⿏标移开后点样式恢复thiss.style.background = "";}//从输⼊提⽰框中选择关键字并查询function selectResult(index) {if(index<0){return;}if (erAgent.indexOf("MSIE") > 0) {document.getElementById("keyword").onpropertychange = null;document.getElementById("keyword").onfocus = focus_callback;}//截取输⼊提⽰的关键字部分var text = document.getElementById("divid" + (index + 1)).innerHTML.replace(/<[^>].*?>.*<\/[^>].*?>/g,"");var cityCode = document.getElementById("divid" + (index + 1)).getAttribute('data');document.getElementById("keyword").value = text;document.getElementById("result1").style.display = "none";//根据选择的输⼊提⽰关键字查询mapObj.plugin(["AMap.PlaceSearch"], function() {var msearch = new AMap.PlaceSearch(); //构造地点查询类AMap.event.addListener(msearch, "complete", placeSearch_CallBack); //查询成功时的回调函数msearch.setCity(cityCode);//console.log(cityCode);msearch.search(text); //关键字查询查询});}//定位选择输⼊提⽰关键字function focus_callback() {if (erAgent.indexOf("MSIE") > 0) {document.getElementById("keyword").onpropertychange = autoSearch;}}//输出关键字查询结果的回调函数function placeSearch_CallBack(data) {//清空地图上的InfoWindow和MarkerwindowsArr = [];marker = [];mapObj.clearMap();var resultStr1 = "";var poiArr = data.poiList.pois;var resultCount = poiArr.length;for (var i = 0; i < resultCount; i++) {resultStr1 += "<div id='divid" + (i + 1) + "' onmouseover='openMarkerTipById1(" + i + ",this)' onmouseout='onmouseout_MarkerStyle(" + (i + 1) + ",this)' style=\"font-size: 12px;cursor:pointer;padding:0px 0 4px 2px; border-bottom:1px solid resultStr1 += TipContents(poiArr[i].type, poiArr[i].address, poiArr[i].tel) + "</td></tr></table></div>";addmarker(i, poiArr[i]);}mapObj.setFitView();}//⿏标滑过查询结果改变背景样式,根据id打开信息窗体function openMarkerTipById1(pointid, thiss) {thiss.style.background = '#CAE1FF';windowsArr[pointid].open(mapObj, marker[pointid]);}//添加查询结果的marker&infowindowfunction addmarker(i, d) {var lngX = d.location.getLng();var latY = d.location.getLat();var markerOption = {map:mapObj,icon:"/images/" + (i + 1) + ".png",position:new AMap.LngLat(lngX, latY)};var mar = new AMap.Marker(markerOption);marker.push(new AMap.LngLat(lngX, latY));var infoWindow = new Window({content:"<h3><font color=\"#00a6ac\"> " + (i + 1) + ". " + + "</font></h3>" + TipContents(d.type, d.address, d.tel), size:new AMap.Size(300, 0),autoMove:true,offset:new AMap.Pixel(0,-30)});windowsArr.push(infoWindow);var autoData = function (e) {var nowPosition = mar.getPosition(),lng_str = nowPosition.lng,lat_str = t;infoWindow.open(mapObj, nowPosition);document.getElementById("lngX").value = lng_str;document.getElementById("latY").value = lat_str;AMap.service('AMap.Geocoder',function(){//回调函数//实例化Geocodergeocoder = new AMap.Geocoder({city: ""//城市,默认:“全国”});var lnglatXY=[lng_str, lat_str];//地图上所标点的坐标geocoder.getAddress(lnglatXY, function(status, result) {if (status === 'complete' && === 'OK') {//获得了有效的地址信息://即,result.regeocode.formattedAddress//console.log(result);var city = result.regeocode.addressComponent.city;}else{var city = '获取失败';//获取地址失败}document.getElementById("city").value=city;console.log(city);});})};AMap.event.addListener(mar, "mouseover", autoData);}//infowindow显⽰内容function TipContents(type, address, tel) { //窗体内容if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {type = "暂⽆";}if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {address = "暂⽆";}if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {tel = "暂⽆";}var str = " 地址:" + address + "<br /> 电话:" + tel + " <br /> 类型:" + type;return str;}function keydown(event){var key = (event||window.event).keyCode;var result = document.getElementById("result1")var cur = result.curSelect;if(key===40){//downif(cur + 1 < result.childNodes.length){if(result.childNodes[cur]){result.childNodes[cur].style.background='';}result.curSelect=cur+1;result.childNodes[cur+1].style.background='#CAE1FF';document.getElementById("keyword").value = result.tipArr[cur+1].name;}}else if(key===38){//upif(cur-1>=0){if(result.childNodes[cur]){result.childNodes[cur].style.background='';}result.curSelect=cur-1;result.childNodes[cur-1].style.background='#CAE1FF';document.getElementById("keyword").value = result.tipArr[cur-1].name;}}else if(key === 13){var res = document.getElementById("result1");if(res && res['curSelect'] !== -1){selectResult(document.getElementById("result1").curSelect);}}else{autoSearch();}}</script></body></html>。

前端获取当前经纬度(gps,高德)

前端获取当前经纬度(gps,高德)

前端获取当前经纬度(gps,⾼德)⽅法介绍:1. 该⽅法是个 promise 对象,因为不管是⽤ GPS 还是⾼德定位都是异步的2. ⽅法优先是⽤ h5 ⾃带 API 进⾏ GPS 定位,如果获取不到位置会使⽤⾼德定位(⾼德定位需要⾼德的key),如果都没获取到,那就经纬度都返回 03. 该 promise 封装的很拙略,能⼒⾄此,会慢慢优化的,本来使⽤的正常⽅法加回调函数处理获取到的经纬度,但考虑再三还是使⽤promise 能好点注意:1. 现在很多浏览器需要加密协议的链接才能获取到⽤户位置,保险起见,请使⽤加密协议的链接2. 使⽤⾼德定位需要在⾼德那⾥申请key3. 如果需要精度⾼或者后续还要使⽤⾼德地图对经纬度做其他处理,需要将 gps 获取到的经纬度转成⾼德经纬度,项⽬头部引得GPS2AMAP就是处理这个的,代码在下⾯1/*2该⽅法暴露出去的是⼀个promise,经纬度在resolve的第⼀个参数⾥3使⽤⽅法: startLocation.then(({lat, lng}) => {这⾥就是你的⽅法})4*/56// 将gps 经纬度转为⾼德经纬度,精度要求⾼的需要这个东西7 import {8 GPS9 } from './GPS2AMAP'10 let callback = null// promise 的 resolve会赋值给这个函数11// gps 定位成功回调12 const onSuccess = (position) => {13 const {14 latitude: lat,15 longitude: lng16 } = position.coords17 const exchange = GPS.gcj_encrypt(Number.parseFloat(lat), Number.parseFloat(lng)) // 对精度要求不⾼可以省略这步,把上⾯获取到的经纬度直接传给saveLocation18 console.log('gps定位', `${t}-${exchange.lng}`)19 saveLocation(t, exchange.lng)20 }21// gps 定位失败回调22 const onError = () => {23 initAMAP()24 console.error('gps失败')25 }26// 初始化⾼德,加载⾼德js27 const initAMAP = () => {28 const key = 'xxxxxxxxxxx', // 从⾼德买来的key29 MP = new Promise(function (resolve, reject) {30 window.init = function () {31 resolve(AMap)32 };33 let script = document.createElement("script");34 script.type = "text/javascript";35 script.src = "///maps?v=1.4.6&key="+key+"&callback=init";36 script.onerror = reject;37 document.head.appendChild(script);38 })39 MP.then(function (AMap) {40 startAMAPLocation(AMap)41 }).catch(err=>{42 console.error(JSON.stringify(err));43 })44 }4546// 开始⾼德定位47 const startAMAPLocation = (AMap) => {48 AMap.plugin('AMap.Geolocation', function () {49var geolocation = new AMap.Geolocation({50 enableHighAccuracy: true, //是否使⽤⾼精度定位,默认:true51 timeout: 8000, //超过10秒后停⽌定位,默认:5s52 buttonPosition: 'RB', //定位按钮的停靠位置53 buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)54 zoomToAccuracy: true, //定位成功后是否⾃动调整地图视野到定位点55 });56// map.addControl(geolocation);57 geolocation.getCurrentPosition(function (status, result) {58if (status == 'complete') {59 console.log('⾼德: ', `${t},${result.position.lng}`)60 saveLocation(t, result.position.lng)61 } else {62 console.error('⾼德失败')63 saveLocation(0, 0)64 }65 });66 });67 }68// 处理获取到的经纬度69 const saveLocation = (lat = 0, lng = 0) => {70 lat && (lat = parseFloat(lat).toFixed(6))71 lng && (lng = parseFloat(lng).toFixed(6))72typeof callback === 'function' && callback({lat, lng})73 }7475// promise, resolve的第⼀个参数就是经纬度,76 const startLocation = new Promise((resolve, reject) => {77 callback = resolve78 const options = {79 enableHighAccuracy: true,80 maximumAge: 1000,81 timeout: 500082 }83if (navigator.geolocation) {84 navigator.geolocation.getCurrentPosition(onSuccess, onError, options)85 } else {86 saveLocation(0, 0)87 console.error('您的浏览器不⽀持地理位置定位')88 }89 })90 export default startLocation这⾥ GPS2AMAP.js ,这个⽅法是这位⽼哥的,1 export const GPS = {2 PI : 3.14159265358979324,3 x_pi : 3.14159265358979324 * 3000.0 / 180.0,4 delta : function (lat, lng) {5var a = 6378245.0; // a: 卫星椭球坐标投影到平⾯地图坐标系的投影因⼦。

经纬度定位工具高德

经纬度定位工具高德

经纬度定位工具高德在现代社会中,随着科技的不断发展,定位技术已经成为了我们生活中不可或缺的一部分。

无论是出行导航、地图浏览,还是物流追踪、位置共享等,准确的定位信息都是确保各项服务能够有效运作的关键。

而高德地图作为国内领先的地理信息服务供应商,其经纬度定位工具更是受到了广大用户的青睐。

高德地图简介高德地图是由阿里巴巴旗下的高德公司开发和运营的一款地理信息服务产品。

它提供了全面、准确、实时的地理信息数据,包括街道地图、卫星地图、交通态势、地理编码、路径规划等功能,满足了人们在生活、工作中对地理位置信息的各种需求。

高德地图凭借其精准的定位和详细的地图信息,成为国内最受欢迎的导航和地图浏览应用之一。

在高德地图的背后,经纬度定位工具则是这一工具的核心。

经纬度定位工具的原理经纬度是地球上任意一个点的地理坐标,在地理坐标系中用经度和纬度来表示。

经度是表示一个点在东西方向上的位置,而纬度则是表示一个点在南北方向上的位置。

经度的范围是-180到180度,纬度的范围是-90到90度。

经纬度定位工具就是通过获取设备所处的经纬度信息,来确定设备在地球上的位置。

在移动设备中,可以通过GPS、基站定位等技术来获取经纬度信息。

高德地图就是通过利用这些技术,来提供准确的地理位置服务。

经纬度定位的应用经纬度定位在现代社会中被广泛应用于各个领域。

下面我们来看一些经纬度定位工具在实际应用中的案例。

出行导航出行导航是经纬度定位工具最常见的应用之一。

通过获取设备的经纬度信息,高德地图可以帮助用户进行导航,提供最佳的行车路线和交通情况。

无论是驾车、步行、骑行还是公共交通,高德地图都能够根据设备的位置信息,为用户提供准确、实时的导航服务。

地图浏览高德地图还提供了详细的街道地图和卫星地图,用户可以通过经纬度定位工具,在地图上快速定位到具体的位置。

不仅如此,用户还能够进行地图放大、缩小、旋转等操作,以便更清楚地了解目标区域的地理信息。

地理编码地理编码是将地址转换成经纬度坐标的过程,而经纬度定位工具可以帮助实现这一功能。

根据经纬度,如何获取地址(经纬度解析中文地址)

根据经纬度,如何获取地址(经纬度解析中文地址)

根据经纬度,如何获取地址(经纬度解析中文地址)移动开发中和poi数据开发中,需要通过经纬度,获取省、市、区(县)等中文地址,这个一直没有标准的技术解决方案,LBS数据中心经过努力,完全解决了这一问题。

具体的实现方式如下:国内唯一权威、标准的经纬度解析数据库,根据精度和纬度每变化0.01,就解析一次标准的地址,完全覆盖全国,数据量980万条。

数据样式:百度地图数据(poi数据)的技术解决方案百度地图目前拥有超过2000完的地图数据,数据的格式包含了商户数据、道路数据、楼宇数据、社区数据、村庄数据等,数据包含了类别、经纬度、电话、名称等,数据格式如下:mapabc地图(也叫高德系列,包含谷歌等地图数据)全国兴趣点poi商户数据共1500多万条,包含地址、电话、经纬度、类别,CSV格式。

谷歌数据格式如下:数据的获取和更多的信息可以查看官方新浪博客:/u/2928794464数据获取和技术QQ咨询:2640056519官方博客拥有以下数据库:纠偏数据库(google地图)精度为0.01:经纬度每变化0.01,取一次偏移值,共980万条,access文件约600mb,误差5~10米。

精度为0.001:经纬度每变化0.001,取一次偏移值,共9亿条,csv文件共20gb,误差约2米。

百度地图纠偏数据库精度0.01,共2800万条全国商户数据poimapabc地图(也叫高德系列,包含谷歌等地图数据)全国兴趣点poi商户数据共1500多万条,包含地址、电话、经纬度、类别,CSV格式。

baidu百度地图poi:全国超过2000万条,永久免费更新技术问题二:各类地图的经纬度偏移的权威技术解决大家在做gps开发中经常会使用到经纬度数据,在开发中,你会发现一个问题,就是每个点的数据都会有偏移,这个就是经纬度偏移问题,那如何解决呢?这个就是需要用到权威的官方的(必须是官方的)纠偏数据库了!数据获取的方式也在新浪博客里面啊!地图经纬度纠偏(gps经纬度偏移及纠偏方法)以上非广告啊,是我在多年移动开发的经验分享,大家也可以和我做技术交流!技术案例:gps数据为什么在地图上的显示会有几百米甚至更多的偏移,这个就是中国国家测绘局的规定,为了安全期间,要求地图的出版商必须加入偏移规则,目前最权威和官方的解决方式就是使用纠偏数据库,百度和谷歌的纠偏数据库都是不一样的,但使用方法相同,下面我来介绍一下:下面是数据库的格式:中国地图经纬度偏移修正数据库,精度:0.01精度,数据量:9813676 条。

通过网格拆分高德地图

通过网格拆分高德地图

通过⽹格拆分⾼德地图 因为爬⾍需要,如⼤众点评通过距离获取商铺,以及⾼德poi获取有数量限制。

就想到通过⽹格的⽅式,把⾼德地图拆分成⼀个⼀个的格⼦,获取对应的经纬度,然后通过对应的经纬度去爬取收据。

思路:  ⾸先获取城市的边界范围,根据边界画出⼀个矩形。

然后通过 new AMap.LngLat获取相应的点。

但是考虑到绘制的会远⼤于该城市实际范围,在城市内部再绘制⼀个矩形。

外围矩形每五公⾥拆分⼀次,内部矩形每公⾥拆分⼀次。

主要代码如下var x1 = new AMap.LngLat(left_lng, left_lat)var x2 = new AMap.LngLat(right_lng, left_lat)var y = new AMap.LngLat(left_lng, right_lat)var center_x1 = new AMap.LngLat(center_left_lng, center_left_lat)var center_x2 = new AMap.LngLat(center_right_lng, center_left_lat)var center_y = new AMap.LngLat(center_left_lng, center_right_lat)var x_distance = x1.distance(x2);var y_distance = x1.distance(y);var center_x_distance = center_x1.distance(center_x2);var center_y_distance = center_x1.distance(center_y);console.log(x_distance, y_distance)console.log(center_x_distance, center_y_distance)drawGrad(x_distance, y_distance);function drawGrad(x, y) {//x,y代表的是距离var x_total = Math.floor(x / km);//⾸尾,故点多1var y_total = Math.floor(y / km);console.log(x_total, y_total)for (var i = 0; i < x_total + 1; i++) {for (var j = 0; j < y_total + 1; j++) {let point = southWest.offset(km * i, -km * j)//在内部矩形,则跳过if ((center_left_lng <= point.lng && point.lng <= center_right_lng) && (center_right_lat <= t && t <= center_left_lat)) {continue}pointsObj[i + "_" + j] = point.lng + ',' + tif (i > 0 && j > 0) {let last_point = pointsObj[(i - 1) + '_' + (j - 1)];if(!last_point){continue}arrList.push(last_point+ '|' + pointsObj[i + '_' + j]) }var bounds2 = new AMap.Bounds(southWest, point) var rectangle2 = new AMap.Rectangle({bounds: bounds2,strokeColor: '#000',strokeWeight: 1,strokeStyle: 'dashed',fillColor: 'transparent',})rectangle2.setMap(map)if (i == x_total && j == y_total) {// console.error(Date.parse(new Date()))console.log(arrList.length)console.log(JSON.stringify(arrList))}}}}。

vue-amap geolocationcallback方法

vue-amap geolocationcallback方法

vue-amap geolocationcallback方法
"vue-amap geolocationcallback方法" 这句话指的是 Vue-AMap 库中用于处理地理位置信息的回调方法。

Vue-AMap 是一个基于Vue.js 和高德地图API 的组件库,它提供了丰富的地图功能,包括地理位置定位。

在 Vue-AMap 中,geolocationcallback是一个方法,用于处理地理位置信息获取的回调。

当用户请求获取地理位置信息时,该方法会被调用。

通过这个方法,你可以获取到用户的经纬度坐标、位置信息等,并可以在回调函数中进行进一步的处理,比如在地图上标记用户的位置,或者根据位置信息执行其他相关操作。

具体来说,geolocationcallback方法通常接收一个参数,该参数包含地理位置信息的相关数据。

你可以在回调函数中访问这些数据,并根据需要进行处理。

总结来说,vue-amap geolocationcallback方法是 Vue-AMap 库中用于处理地理位置信息获取的回调方法。

通过这个方法,你可以获取到用户的地理位置信息,并在回调函数中进行进一步的处理。

高德AMAP行政区划边界及经纬度获取

高德AMAP行政区划边界及经纬度获取

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>行政区划边界</title><link rel="stylesheet" type="text/css"href="/Public/css/demo.Default.css" /><script language="javascript"src="/maps?v=1.3&key=7de8697669288fc848e 12a08f58d995e"></script><script language="javascript">var mapObj,district;/**初始化地图对象,加载地图*/function mapInit(){mapObj = new AMap.Map("iCenter",{view: new AMap.View2D({center:new AMap.LngLat(116.397428,39.90923),//地图中心点zoom:10 //地图显示的缩放级别})});initPolygon();}function initPolygon(){//加载云图层插件mapObj.plugin('AMap.DistrictSearch', function () {var opts = {subdistrict: 0, //返回下一级行政区extensions: 'all', //返回行政区边界坐标组等具体信息level:'city'//查询行政级别为市};//实例化DistrictSearchdistrict = new AMap.DistrictSearch(opts);//查询成功时的回调函数,定义如何展示请求返回结果AMap.event.addListener(district, 'complete', function(e){var bounds = e.districtList[0].boundaries;var polygons = [];var arr = [];if(bounds){for(var i =0, l = bounds.length;i < l; i++){//生成行政区划polygonvar polygon = new AMap.Polygon({map:mapObj,strokeWeight:1,path:bounds[i],fillOpacity:0.7,fillColor:'#CCF3FF',strokeColor:'#CC66CC'});polygons.push(polygon);}mapObj.setFitView();//地图自适应}for(var i=0;i<bounds.length;i++){var lnglatArr = polygons[i].getPath();for(var j=0;j<lnglatArr.length;j++){arr.push(lnglatArr[j].toString());}}document.getElementById("info").innerText = arr.join(";");arr = [];//释放数组});});}/**叠加云数据图层*/function drawPolygon() {var level = document.getElementById("level").value;var name = document.getElementById("district").value;var isClear =document.getElementById("isClear").value;if(district == ""){alert("请输入行政区名称!");return false;}if(isClear == 1){mapObj.clearMap();//清除地图覆盖物}district.setLevel(level);//行政区查询 districtdistrict.search(name); //行政区查询}</script></head><body onLoad="mapInit()"><div id="iCenter"></div><div style="height: 80px;width:1000px;"><table style="width:100%;height:100%;" align="center"> <tr height="40px"><td width="15%" align="right">选择行政区级别:</td><td width="35%"><select id="level"><option value="country">国家</option><option value="province">省/直辖市</option><option value="city" selected="selected">市</option><option value="district">区/县</option><option value="biz_area">商圈</option></select></td><td width="50%" rowspan="4" align="center"height="160px"><textarea id="info" rows="3"style="width:100%;height:100%;padding: 2px 0px 0px 5px; font-size: 12px; color: red; overflow-y: auto"></textarea></td></tr><tr height="40px"><td align="right">行政区名称:</td><td><input type="text" name="district"id="district"/></td></tr><tr height="40px"><td align="right">是否清除覆盖物:</td><td><select id="isClear"><option value="1" selected="selected">是</option><option value="0">否</option></select></td></tr><tr height="40px"><td colspan="2" align="center"><input type="button" value="绘制" onclick="drawPolygon()"/></td></tr></table></div></body></html>。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
<title>行政区划边界</title>
<link rel="stylesheet" type="text/css"
href="/Public/css/demo.Default.css" />
<script language="javascript"
src="/maps?v=1.3&key=7de8697669288fc848e 12a08f58d995e"></script>
<script language="javascript">
var mapObj,district;
/*
*初始化地图对象,加载地图
*/
function mapInit(){
mapObj = new AMap.Map("iCenter",{
view: new AMap.View2D({
center:new AMap.LngLat(116.397428,39.90923),//地图中心点
zoom:10 //地图显示的缩放级别
})});
initPolygon();
}
function initPolygon(){
//加载云图层插件
mapObj.plugin('AMap.DistrictSearch', function () {
var opts = {
subdistrict: 0, //返回下一级行政区
extensions: 'all', //返回行政区边界坐标组等具体信息
level:'city'//查询行政级别为市
};
//实例化DistrictSearch
district = new AMap.DistrictSearch(opts);
//查询成功时的回调函数,定义如何展示请求返回结果
AMap.event.addListener(district, 'complete', function(e){
var bounds = e.districtList[0].boundaries;
var polygons = [];
var arr = [];
if(bounds){
for(var i =0, l = bounds.length;i < l; i++){
//生成行政区划polygon
var polygon = new AMap.Polygon({
map:mapObj,
strokeWeight:1,
path:bounds[i],
fillOpacity:0.7,
fillColor:'#CCF3FF',
strokeColor:'#CC66CC'
});
polygons.push(polygon);
}
mapObj.setFitView();//地图自适应
}
for(var i=0;i<bounds.length;i++){
var lnglatArr = polygons[i].getPath();
for(var j=0;j<lnglatArr.length;j++){
arr.push(lnglatArr[j].toString());
}
}
document.getElementById("info").innerText = arr.join(";");
arr = [];//释放数组
});
});
}
/*
*叠加云数据图层
*/
function drawPolygon() {
var level = document.getElementById("level").value;
var name = document.getElementById("district").value;
var isClear =
document.getElementById("isClear").value;
if(district == ""){
alert("请输入行政区名称!");
return false;
}
if(isClear == 1){
mapObj.clearMap();//清除地图覆盖物
}
district.setLevel(level);//行政区查询 district
district.search(name); //行政区查询
}
</script>
</head>
<body onLoad="mapInit()">
<div id="iCenter"></div>
<div style="height: 80px;width:1000px;">
<table style="width:100%;height:100%;" align="center"> <tr height="40px">
<td width="15%" align="right">选择行政区级别:</td>
<td width="35%">
<select id="level">
<option value="country">国家</option>
<option value="province">省/直辖市</option>
<option value="city" selected="selected">市</option>
<option value="district">区/县</option>
<option value="biz_area">商圈</option>
</select>
</td>
<td width="50%" rowspan="4" align="center"
height="160px">
<textarea id="info" rows="3"
style="width:100%;height:100%;padding: 2px 0px 0px 5px; font-size: 12px; color: red; overflow-y: auto"></textarea>
</td>
</tr>
<tr height="40px">
<td align="right">行政区名称:</td>
<td><input type="text" name="district"
id="district"/></td>
</tr>
<tr height="40px">
<td align="right">是否清除覆盖物:</td>
<td><select id="isClear">
<option value="1" selected="selected">是
</option>
<option value="0">否</option>
</select>
</td>
</tr>
<tr height="40px">
<td colspan="2" align="center"><input type="button" value="绘制" onclick="drawPolygon()"/></td>
</tr>
</table>
</div>
</body>
</html>。

相关文档
最新文档