当前位置:网站首页>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
边栏推荐
- In JS, t, = > Analysis of
- stm32入门开发板选野火还是正点原子呢?
- The system cannot be started after AHCI is enabled
- MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
- Future 用法详解
- 2022年茶艺师(初级)考试模拟100题及模拟考试
- How to manually implement the mechanism of triggering garbage collection in node
- 122. The best time to buy and sell stocks II - one-time traversal
- [batch change MySQL table and corresponding codes of fields in the table]
- 给 el-dialog 增加拖拽功能
猜你喜欢
随机推荐
41. 缺失的第一个正数
If you start from zero according to the frame
Index: teach you index from zero basis to proficient use
Write a regular
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
JVM class loading mechanism
ES6 new method
超分之TDAN
ECMAScript history
92. 反转链表 II-字节跳动高频题
Some questions some questions some questions some questions
958. Complete binary tree test
Arithmetic expression
Construction of functions in C language programming
470. Rand10() is implemented with rand7()
Model problems of stock in and stock out and inventory system
Learning record of uni app dark horse yougou project (Part 2)
2022年流动式起重机司机国家题库模拟考试平台操作
土地覆盖/利用数据产品下载
读《Software Engineering at Google》(15)









