网站首页 建站知识 正文
很多人都想在页面调用百度地图,那么如何调用呢,看百度官方文档需要调用api接口,是不是太麻烦了,今天教你一个小白都会的方法,只需要会改路径就行。
在百度地图调用的地方写入ifrom框架,例如
<iframe frameborder="0" height="400" scrolling="no" src="/ditu/jiulishanditu.html" width="100%"></iframe>
在网站对应的/ditu/jiulishanditu.html地方新建一个html文档,文档里面直接放入地图的代码,图片的路径要对应好
地图代码参考下面代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="xxx" />
<meta name="description" content="xxx" />
<title>xxx</title>
<!--引用百度地图API-->
<script src="http://api.map.baidu.com/api?type=webgl&v=1.0&ak=uvN6vatvU44OQ0a9yuXdQZxTXODHGuLI"></script>
</head>
<style>
body,
html,
#container {
overflow: hidden;
width: 100%;
height: 400px;
margin: 0;
font-family: "微软雅黑";
}
.info {
z-index: 999;
width: auto;
min-width: 22rem;
padding: .75rem 1.25rem;
margin-left: 1.25rem;
position: fixed;
top: 1rem;
background-color: #fff;
border-radius: .25rem;
font-size: 14px;
color: #666;
box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
}
</style>
<body>
<!--百度地图容器-->
<div id="container"></div>
<div class="" id="info" style="display: none;">
<h4 style='margin:0 0 5px 0;'>昌平九里山公墓二区</h4>
<img style='float:right;margin:0 4px 22px' id='imgDemo' src='/ditu/jiulishan.jpg' width='120' height='104' />
<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>
xxx
</p>
<p> <h3 style='margin:0 0 5px 0;'>电话:xxxxxxxxxxxx</h3> </p>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var map = new BMapGL.Map('container');
var point = new BMapGL.Point(116.328692,40.21217);
map.centerAndZoom(point, 12);
map.enableScrollWheelZoom(true);
// 创建添加点标记
var marker = new BMapGL.Marker(point);
map.addOverlay(marker);
// 创建图文信息窗口
var sContent = document.getElementById('info').innerHTML
var infoWindow = new BMapGL.InfoWindow(sContent);
map.openInfoWindow(infoWindow, point);
// marker添加点击事件
marker.addEventListener('click', function () {
this.openInfoWindow(infoWindow);
// 图片加载完毕重绘infoWindow
document.getElementById('imgDemo').onload = function () {
infoWindow.redraw(); // 防止在网速较慢时生成的信息框高度比图片总高度小,导致图片部分被隐藏
};
});
</script>
</html>
红色地方填写坐标,展示的最终结果如下所示
- 上一篇: 图片点击放大,可以翻页关闭怎么做。
- 下一篇: 帝国cms如何根据自定义字段调用相同字段的文章
你 发表评论:
欢迎- 2023-02-27百度小程序怎么用 标签显示前端样式
- 2022-12-07帝国cms如何在首页和列表页分别调用文章栏目名称
- 2022-12-01帝国cms如何清理全部tag标签
- 2022-11-29如何重新安装zblog,在已有数据库的情况下
- 2022-11-24python,py采集过程中谷歌内核版本需要更新怎么操作
- 2022-07-14css如何设置首航缩进两字符
- 2022-07-06帝国cms如何登陆后台地址,如何让id从1开始
- 2022-03-31如何用php随机生成一个数字
- 搜索
- 文章归档
本文暂时没有评论,来添加一个吧(●'◡'●)