参考高德地图API文档:https://lbs.amap.com/api/javascript-api/example/geocoder/geocoding
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>联系我们</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<style>
#container{
width: 450px;
height: 250px;
background: #FAFAFA;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=8010097315ab501d7866f25f2a8e0c4e&plugin=AMap.Geocoder"></script>
<script>
var map = new AMap.Map("container", {
resizeEnable: true
});
var geocoder,marker;
window.onload = function geoCode() {
if(!geocoder){
geocoder = new AMap.Geocoder({
city: "010", //城市设为北京,默认:“全国”
});
}
var address = "安徽省......【详细地理位置】";
geocoder.getLocation(address, function(status, result) {
if (status === 'complete'&&result.geocodes.length) {
var lnglat = result.geocodes[0].location
if(!marker){
marker = new AMap.Marker();
map.add(marker);
}
marker.setPosition(lnglat);
map.setFitView(marker);
}else{
log.error('根据地址查询位置失败');
}
})
}
</script>
</body>
</html>