当前位置:网站首页>百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!
百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!
2022-06-26 05:04:00 【你好骚啊】
在项目中引入了百度地图,运行是发现标注的位置发生了偏移?
按道理是按照坐标定位的,为啥跑到左上角去了,刚开始百思不得其解。
废话不多说,直接上能够处理的代码。
加入这一行就可以了:map.panBy(580, 150);
//map.panBy(580, 150);
//第一个参数是宽度
//第二个参数是高度
//基本设置为你放 id = "allmap" 的div的一半,就居中了。
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(114.236412,22.691258);
map.centerAndZoom(point, 18);
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
// 添加带有定位的导航控件
var navigationControl = new BMap.NavigationControl({
// 靠左上角位置
anchor: BMAP_ANCHOR_TOP_LEFT,
// LARGE类型
type: BMAP_NAVIGATION_CONTROL_LARGE,
// 启用显示定位
enableGeolocation: true
});
map.addControl(navigationControl);
//解决标注点不居中的问题
map.panBy(580, 150);//中心点偏移多少像素(width,height)为div 宽高的1/2;
</script>
完美解决!敬礼,撒花。
边栏推荐
猜你喜欢
MySql如何删除所有多余的重复数据
Differences between TCP and UDP
Codeforces Round #802 (Div. 2)(A-D)
What is UWB in ultra-high precision positioning system
6.1 - 6.2 公钥密码学简介
2.22.2.14
2. < tag dynamic programming and conventional problems > lt.343 integer partition
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
6.1 - 6.2 Introduction à la cryptographie à clé publique
zencart新建的URL怎么重写伪静态
随机推荐
YOLOV5超参数设置与数据增强解析
6.1 - 6.2 公鑰密碼學簡介
Collections and dictionaries
Multipass Chinese document - use instance command alias
【Unity3D】人机交互Input
Status of processes and communication between processes
两步处理字符串正则匹配得到JSON列表
Keras actual combat cifar10 in tensorflow
Introduction to classification data cotegory and properties and methods of common APIs
关于支付接口回调地址参数字段是“notify_url”,签名过后的特殊字符url编码以后再解码后出现错误(¬ , ¢, ¤, £)
2022.2.13
The first gift of the project, the flying oar contract!
广和通联合安提国际为基于英伟达 Jetson Xavier NX的AI边缘计算平台带来5G R16强大性能
How MySQL deletes all redundant duplicate data
Modify the case of the string title(), upper(), lower()
Zuul implements dynamic routing
图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译
Lstms in tensorflow_ Cell actual combat
What is UWB in ultra-high precision positioning system
Muke.com actual combat course