当前位置:网站首页>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
边栏推荐
- 列表的使用-增删改查
- Change Oracle to MySQL
- PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
- Header built-in object
- 2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
- How to sort the numbers with text in Excel from small to large instead of the first number
- Tell the truth of TS
- 958. 二叉树的完全性检验
- Qt 修改UI没有生效
- 122. 买卖股票的最佳时机 II-一次遍历
猜你喜欢
Compare the performance of query based on the number of paging data that meet the query conditions
JVM class loading mechanism
HCIP第五次实验
干货 | 快速抽取缩略图是怎么练成的?
394. String decoding - auxiliary stack
Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
How to change input into text
Gets the time range of the current week
QT modification UI does not take effect
开源按键组件Multi_Button的使用,含测试工程
随机推荐
JS forms the items with the same name in the array object into the same array according to the name
2021 Great Wall Cup WP
读《Software Engineering at Google》(15)
How to use the input table one-way service to send (occupy less) picture files (body transmission)? FileReader built-in object involved
Dry goods | how to extract thumbnails quickly?
2022年流动式起重机司机国家题库模拟考试平台操作
SystemVerilog(六)-变量
node中,如何手动实现触发垃圾回收机制
PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
386. Dictionary order (medium) - iteration - full arrangement
[appium] write scripts by designing Keyword Driven files
31. Next arrangement
In ancient Egypt and Greece, what base system was used in mathematics
Where is the configuration file of tidb server?
嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
Use of todesk remote control software
EasymodbusTCP之clientexample解析
Model problems of stock in and stock out and inventory system
Client example analysis of easymodbustcp
394. String decoding - auxiliary stack