当前位置:网站首页>Gaode map search, drag and drop query address
Gaode map search, drag and drop query address
2022-04-23 17:45:00 【A long summer】
demo- design sketch


Code –( Referenced map ,key Replace the value with your own )
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Map search and drag location </title>
<style>
#mapContainer{
position: relative;
width: calc(100vw-20px);
height: calc(100vh - 30px);
background: #fff;
z-index: 1;
overflow: hidden;
}
.searchBox{
position: absolute;
left: 20px;
top: 20px;
z-index: 2;
}
.searchBox #keyword{
height: 30px;
line-height: 30px;
width: 260px;
padding: 0 5px;
}
.searchResult{
position: absolute;
bottom: 50px;
left: 30px;
z-index: 2;
height: 100px;
width: 400px;
background: #fff;
border-radius: 8px;
padding: 20px;
cursor: default;
}
</style>
</head>
<body>
<div id="mapContainer">
<div class="searchBox">
<input id='keyword' type="text" placeholder=" Please enter the query location ">
</div>
<div class="searchResult">
<p>
<span> Longitude and latitude :</span>
<span id="lnglat"></span>
</p>
<p>
<span> Address :</span>
<span id="address"></span>
</p>
</div>
</div>
<div style="display: none">
<script type="text/javascript" src="http://webapi.amap.com/maps?v=2.0&key=${ Your map key value }&plugin=AMap.ToolBar,AMap.Autocomplete,AMap.PlaceSearch,AMap.Walking,AMap.Geocoder"></script>
<script src="http://webapi.amap.com/ui/1.0/main.js?v=202112071452"></script>
<script>
AMapUI.loadUI(['misc/PositionPicker'],PositionPicker => {
// Initialize the user area as the center point of the map
const mapConfig = {
zoom: 15, // Map zoom level
center: ['117.227237', '31.820513'],
lang: "zh_cn"
}
let mapView = new AMap.Map('mapContainer', mapConfig);
// Construction point marker
// var m3 = new AMap.Marker({
// position: [117.224362,31.820447],
// icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png"
// });
// mapView.add(m3);
// Drag and drop the map
var positionPicker = new PositionPicker({
mode: 'dragMarker',//dragMap: Drag and drop the map ,dragMarker: Drag point
map: mapView,
iconStyle: { // Custom look
url: 'http://webapi.amap.com/theme/v1.3/markers/b/mark_r.png',
ancher: [24, 40],
size: [24, 30]
}
});
positionPicker.on('success', function (positionResult) {
// Drag the successful callback positionResult There is something you want
// console.log(' Drag and drop ',positionResult)
document.getElementById('lnglat').innerHTML = positionResult.position.lng+ ','+positionResult.position.lat;
document.getElementById('address').innerHTML = positionResult.address;
});
positionPicker.start();
// Search tips
AMap.plugin('AMap.Autocomplete', function () {
// Instantiation Autocomplete
var autoOptions = {
city: ' Hefei ',
input: "keyword"
}
var auto = new AMap.Autocomplete(autoOptions)
var placeSearch = new AMap.PlaceSearch({
pageSize: 5,
pageIndex: 1,
citylimit: false,
map: mapView,
city: ' Hefei ' // Default city
});
AMap.event.addListener(auto, "select", select); // Register to listen , When a record is selected, it will trigger
AMap.event.addListener(auto, "error", onError); // Register to listen , When a record is selected, it will trigger
// Analyze and locate the correct information
function select(e) {
placeSearch.setCity(e.poi.adcode);
placeSearch.search(e.poi.name); // Keyword query
var info = e.poi;// Geographic Information
console.log(info)
document.getElementById('lnglat').innerHTML = info.location.lng+ ','+info.location.lat;
document.getElementById('address').innerHTML = info.district+ info.address;
}
// Parse the location error message
function onError(data) {
console.log(" seek failed ")
}
})
})
</script>
</div>
</body>
</html>
版权声明
本文为[A long summer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231742193129.html
边栏推荐
- 239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
- 198. Looting - Dynamic Planning
- Ring back to origin problem - byte jumping high frequency problem
- In ancient Egypt and Greece, what base system was used in mathematics
- If you start from zero according to the frame
- 【Appium】通过设计关键字驱动文件来编写脚本
- [appium] write scripts by designing Keyword Driven files
- 剑指 Offer 22. 链表中倒数第k个节点-快慢指针
- 2022年上海市安全员C证操作证考试题库及模拟考试
- Tdan over half
猜你喜欢

嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?

uni-app黑马优购项目学习记录(下)

SiteServer CMS5. 0 Usage Summary

Index: teach you index from zero basis to proficient use

土地覆盖/利用数据产品下载

Use of five routing guards

Summary of common SQL statements

【Appium】通过设计关键字驱动文件来编写脚本

Why do some people say SCM is simple and I have to learn it so hard?

2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
随机推荐
198. 打家劫舍-动态规划
470. Rand10() is implemented with rand7()
Chrome浏览器的跨域设置----包含新老版本两种设置
Manually implement simple promise and its basic functions
[batch change MySQL table and corresponding codes of fields in the table]
Use of five routing guards
土地覆盖/利用数据产品下载
In ancient Egypt and Greece, what base system was used in mathematics
209. 长度最小的子数组-滑动窗口
Error in created hook: "referenceerror:" promise "undefined“
为什么有些人说单片机简单,我学起来这么吃力?
Come out after a thousand calls
2022年流动式起重机司机国家题库模拟考试平台操作
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
122. The best time to buy and sell stocks II - one-time traversal
Halo open source project learning (II): entity classes and data tables
剑指 Offer 22. 链表中倒数第k个节点-快慢指针
Qt 修改UI没有生效
In JS, t, = > Analysis of
The method of changing a value in the array and a value in the object of wechat applet