正在回答 回答被采纳积分+1
2回答
好帮手慕星星
2021-01-22 14:26:46
同学你好,高德地图中有浏览器精确定位,可以看看,是不是想要这种效果:
https://lbs.amap.com/api/javascript-api/example/location/browser-location
上面链接中是获取当前位置的经纬度,如果想要转化为地理位置,可以使用下面的方式转化一下(坐标转地址)
https://lbs.amap.com/api/javascript-api/example/geocoder/regeocoding
祝学习愉快!
好帮手慕久久
2021-01-06 19:04:29
同学你好,可以使用高德地图提供的使用ip的方式获取定位,如下:
代码可参考如下:
1 | <!doctype html><br><html><br><head><br> <meta charset= "utf-8" ><br> <meta http-equiv= "X-UA-Compatible" content= "IE=edge" ><br> <meta name= "viewport" content= "initial-scale=1.0, user-scalable=no, width=device-width" ><br> <title>根据ip定位</title><br> <link rel= "stylesheet" href= "https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" /> <br> <style type= "text/css" ><br> html,body, #container{<br> height:100%;<br> }<br> </style><br></head><br><body><br><div id="container"></div><br><div class="info"><br> <p id='info'></p><br></div><br><script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=dcee67f573cdde2da470cffd5a66b429&plugin=AMap.CitySearch"></script><br><script type="text/javascript"><br> var map = new AMap.Map("container", {<br> resizeEnable: true,<br> center: [116.397428, 39.90923],<br> zoom: 13<br> });<br> //获取用户所在城市信息<br> function showCityInfo() {<br> //实例化城市查询类<br> var citysearch = new AMap.CitySearch();<br> //自动获取用户IP,返回当前城市<br> citysearch.getLocalCity(function(status, result) {<br> if (status === 'complete' && result.info === 'OK') {<br> if (result && result.city && result.bounds) {<br> var cityinfo = result.city;<br> var citybounds = result.bounds;<br> document.getElementById('info').innerHTML = '您当前所在城市:'+cityinfo;<br> //地图显示当前城市<br> map.setBounds(citybounds);<br> }<br> } else {<br> document.getElementById('info').innerHTML = result.info;<br> }<br> });<br> }<br> showCityInfo();<br></script><br></body><br></html><br><br> |
参考文档如下:
https://lbs.amap.com/api/javascript-api/example/location/get-city-name-by-ip-location
如果同学想要更精确的定位,则可以参考该文档,自己尝试扩展下。
祝学习愉快!
3.WebAPP开发与小程序
- 参与学习 人
- 提交作业 622 份
- 解答问题 6815 个
微信带火了小程序,也让前端工程师有了更多的展现机会,本阶段带你从移动基础知识的学习到webAPP开发,及小程序开发,让你PC端与移动端两端通吃。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧