复制 粘贴到html中打开!!!!!
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>地图初始IP城市定位</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
<style type="text/css">
html,body,#container{
height:100%;
}
.info{
width:20rem;
}
</style>
</head>
<body>
<div id="container" style="display: block"></div>
<div class="info">
<p>在初始化地图时,如果center属性缺省,地图默认定位到用户所在城市的中心</p><hr>
<p id='adcode'></p>
</div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key='修改成自己的key'"></script>
<script type="text/javascript">
//初始化地图时,若center属性缺省,地图默认定位到用户所在城市的中心
var map = new AMap.Map('container', {
resizeEnable: true
});
document.getElementById('adcode').innerHTML='当前城市adcode:'+map.getAdcode()+'<br>'+'当前中心点:'+map.getCenter();
console.log(map)
</script>
</body>
</html>
* 如果只要城市的code, 删除多余标签,....new AMap.Map('') , 再调用getAdcode()即可