青岛网站建设新闻资讯

在网站上插入高德地图的方法

时间:2022-07-02 已阅读:2431次 | 作者:青岛网站建设

首页>新闻资讯>建站知识

在网站上插入高德地图的方法分享。

1、在头部body加入以下代码:

<script src="https://webapi.amap.com/maps?v=1.4.15&key=key值"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>

2、正文地图区域,记得给container定义宽和高:

<div id="container"></div>

3、css代码:

#container {width:100%; height: 550px; }

4、底部调用地图js:

<script>
var marker, map = new AMap.Map("container", {
resizeEnable: true,
center: [120.188258,30.121094],
zoom: 16
});
map.setMapStyle('amap://styles/whitesmoke');
marker = new AMap.Marker({
icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [120.188258,30.121094]
});
marker.setMap(map);
</script>
注意: [120.188258,30.121094] 根据具体的地址坐标填写。坐标获取:https://lbs.amap.com/dev/mapstyle/edit?styleid=4bce31e306518094153989f12d3e9804amap:/yles/whitesmoke 为自定义地图样式,如需更改参见:
https://lbs.amap.com/api/javascript-api/guide/map/map-style/



二维码
扫描二维码手机查看该文章

文章引用:https://www.qinghuahulian.com/news/webzhishi/1213.html

相关资讯

Copyright © 2011-2024 青华互联-青岛青华锐思网络科技有限公司 www.qinghuahulian.com All Rights Reserved
鲁公网安备37020202000800号 鲁ICP备14020555号-4 网站地图 百度地图