当前位置:网站首页>让百度地图生成器里的“标注”内容展开--解决方案
让百度地图生成器里的“标注”内容展开--解决方案
2022-07-30 05:50:00 【cplvfx】
这篇文章简单的讲:直接复制文章里的“完整代码”, 修改【坐标】和【公司信息】就完事了
代码
如果你用我写的代码,需要知道下面2个
百度地图生成器:http://api.map.baidu.com/lbsapi/createmap/index.html
百度地图拾取坐标系统:http://api.map.baidu.com/lbsapi/getpoint/index.html
但是,百度地图生成器里的“标注”点,是不会展开的, 我们今天就是想让它展开
效果展示:

只需要关注的代码:
var cp_title=" 郑州英伦电气有限公司";
var cp_content="联系人:王伟(先生) <br/>手 机:137***367<br/> 电 话:0371-***628 <br/> Q Q:128***498 <br/>网址:http://www.xxx.com <br/>地 址:郑州市高新技术开发区檀香路1号";
var cp_lng=113.539696;
var cp_lat=34.804373;
完整代码:
<!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="百度地图,百度地图API,百度地图自定义工具,百度地图所见即所得工具" />
<meta name="description" content="百度地图API自定义地图,帮助用户在可视化操作下生成百度地图" />
<title>百度地图API自定义地图</title>
<!--引用百度地图API-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=v3Cg0hRvbX7cuUSKG2sEklyeP8iw5eye"></script>
</head>
<body>
<!--百度地图容器-->
<div style="width:80%;height:550px;border:#ccc solid 1px;font-size:12px" id="map"></div>
</body>
<script type="text/javascript">
var cp_title=" 郑州英伦电气有限公司";
var cp_content="联系人:王伟(先生) <br/>手 机:137***367<br/> 电 话:0371-***628 <br/> Q Q:128***498 <br/>网址:http://www.xxx.com <br/>地 址:郑州市高新技术开发区檀香路1号";
var cp_lng=113.539696;
var cp_lat=34.804373;
//创建和初始化地图函数:
function initMap(){
createMap();//创建地图
setMapEvent();//设置地图事件
addMapControl();//向地图添加控件
addMapOverlay();//向地图添加覆盖物
}
function createMap(){
map = new BMap.Map("map");
map.centerAndZoom(new BMap.Point(cp_lng,cp_lat),19);
}
function setMapEvent(){
map.enableScrollWheelZoom();
map.enableKeyboard();
map.enableDragging();
map.enableDoubleClickZoom()
}
function addClickHandler(target,window){
target.addEventListener("click",function(){
target.openInfoWindow(window);
});
}
function addMapOverlay(){
var markers = [
{content:cp_content,title:cp_title,imageOffset: {width:-46,height:-21},position:{lat:cp_lat,lng:cp_lng}}
];
for(var index = 0; index < markers.length; index++ ){
var point = new BMap.Point(markers[index].position.lng,markers[index].position.lat);
var marker = new BMap.Marker(point,{icon:new BMap.Icon("http://api.map.baidu.com/lbsapi/createmap/images/icon.png",new BMap.Size(20,25),{
imageOffset: new BMap.Size(markers[index].imageOffset.width,markers[index].imageOffset.height)
})});
var label = new BMap.Label(markers[index].title,{offset: new BMap.Size(25,5)});
var opts = {
width: 200,
title: markers[index].title,
enableMessage: false
};
var infoWindow = new BMap.InfoWindow(markers[index].content,opts);// 创建信息窗口对象
marker.setLabel(label);
addClickHandler(marker,infoWindow);
map.addOverlay(marker);
map.openInfoWindow(infoWindow, map.getCenter()); // 打开信息窗口
};
}
//向地图添加控件
function addMapControl(){
var scaleControl = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
scaleControl.setUnit(BMAP_UNIT_IMPERIAL);
map.addControl(scaleControl);
var navControl = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
map.addControl(navControl);
var overviewControl = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:true});
map.addControl(overviewControl);
}
var map;
initMap();
</script>
</html>修改代码
修改内容
var cp_title="你要展示的标题、店名、公司名";
var cp_content="联系人:XXX(先生) <br/>手 机:137****5367<br/> 电 话:0371-***28 <br/> Q Q:128***98 <br/>网址:http://www.XXXXX.com <br/>地 址:郑州市高新技术开发区檀香路1号";修改坐标
第一步:打开 【百度地图拾取坐标系统】:http://api.map.baidu.com/lbsapi/getpoint/index.html
第二步:找到你要展示的位置
第三步:复制坐标

第四步:修改代码
“,”逗号前面的值给变量cp_lng
“,”逗号后面的值给变量cp_lat
var cp_lng=113.539696;
var cp_lat=34.804373;
第五步:保存-完成
边栏推荐
- 05-Theos
- Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
- 空间顶点到直线的距离计算及其源码
- STL source code analysis: conceptual understanding of iterators, and code testing.
- Test Development Engineer Growth Diary 003 - Interface Automation Framework Construction
- Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug
- AI元学习引入神经科学,医疗效果有望精准提升
- RAID磁盘阵列
- prometheus-tls加密
- Mastering JESD204B (2) – Debugging of AD6676
猜你喜欢

STL源码剖析:迭代器的概念理解,以及代码测试。

prometheus-tls加密
测试开发工程师成长日记010 - Jenkins中的CI/CD/CT(持续集成构建/持续交付/持续测试)

As a test leader, examine several aspects of job candidates

如何理解普吕克坐标(几何理解)

多线程基础(多线程内存,安全,通信,线程池和阻塞队列)

从 Vertex 到 Subgraph 再到 PIE: 并行图计算编程模型概览

Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug

MongoDB-CUD没有R

STL source code analysis: conceptual understanding of iterators, and code testing.
随机推荐
LVM和磁盘配额
Test Development Engineer Growth Diary 003 - Interface Automation Framework Construction
MongoDB - Introduction, Data Types, Basic Statements
02-Use of Cycript
Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps
bin文件夹下的roslyn文件夹
PXE efficient mass network capacity
阿里一面:多线程顺序运行有多少种方法?
Application of graph computing in network security analysis
prometheus监控minio
Detailed explanation of numpy multidimensional array ndarray
Linx common directory & file management commands & VI editor usage introduction
AI元学习引入神经科学,医疗效果有望精准提升
Linux(centos7)下安装MySQL
STL source code analysis: conceptual understanding of iterators, and code testing.
OP tokens and non-transferable NFTs work to build a new digital democracy
Test the basics 01
多线程进阶(锁策略,自旋+CAS,Synchronized,JUC,信号量)
Ingress:从静态图分析到动态图分析
如何理解普吕克坐标(几何理解)