当前位置:网站首页>百度地图——入门教程
百度地图——入门教程
2022-06-25 06:32:00 【Nanchen_42】
目录
一、登录账号以及获取秘钥
获取秘钥


提交之后会出现一个新增的AK也就是所谓的秘钥

这时候就可以直接用来调用了
二、引入地图
<script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=你的秘钥">三、创建地图容器
之后创建一个盒子
<div id="container"></div>四、定义盒子大小
设置盒子大小以及隐藏logo和版权
#container {
margin: 100px auto;
width: 500px;
height: 300px
}
/* 百度地图版权 */
.BMap_cpyCtrl {
display: none;
}
/* 百度地图logo */
.anchorBL {
/* display: none; */
}五、设置地图详细样式
<script type="text/javascript">
var map = new BMapGL.Map("container");
// 允许放大缩小
map.enableScrollWheelZoom(true);
// 创建地图实例
var point = new BMapGL.Point(121.467406, 31.411477, 20);
// 创建标记位置
var marker = new BMapGL.Marker(new BMapGL.Point(121.467406, 31.411477));
// 默认放大倍数
map.centerAndZoom(point, 20);
function addOverlay() {
map.addOverlay(marker); // 增加点
}
addOverlay()
var opts = {
width: 200, // 信息窗口宽度
height: 100, // 信息窗口高度
title: "小朋友专属区", // 信息窗口标题
message: "这里是公寓"
}
var infoWindow = new BMapGL.InfoWindow("地址:上海市xx区xx路xxxxx", opts); // 创建信息窗口对象
marker.addEventListener("click", function () {
map.openInfoWindow(infoWindow, point); //开启信息窗口
});
// 初始化地图,设置中心点坐标和地图级别
var geolocation = new BMapGL.Geolocation();
var geoc = new BMapGL.Geocoder();
console.log(geoc);
</script>效果如下:

如果想要自己获取坐标位置可以使用拾取坐标系统

边栏推荐
- Brief introduction and use of JSON
- [Suanli network] problems and challenges faced by the development of Suanli network
- Why study discrete mathematics
- Analysis report on demand scale and Supply Prospect of global and Chinese thermal insulation materials market during the 14th Five Year Plan period 2022-2028
- [no title] dream notes 2022-02-20
- How two hosts in different network segments directly connected communicate
- @Detailed explanation of valid annotation usage
- Copying DNA
- @The difference between notempty, @notnull and @notblank
- An easy problem
猜你喜欢

How to deploy locally developed SAP ui5 applications to ABAP servers

Sleep quality today 67 points

Wireless industrial Internet of things data monitoring terminal

Location object

What is the slice flag bit

3-7sql injection website instance step 3: attack type and attack strategy

Uni app wechat applet customer service chat function
![[kicad image] download and installation](/img/88/cebf8cc55cb8904c91f9096312859a.jpg)
[kicad image] download and installation

Gb28181 protocol -- timing

We cannot activate inspection type for article master in transaction code MM41?
随机推荐
北京网上开股票账户安全吗?
Global and Chinese gallium nitride (GAN) market output value scale forecast and application prospect analysis report 2022
@Detailed explanation of valid annotation usage
Understand what ICMP Protocol is
Aviator an expression evaluation engine
Count the grid
Ifconfig command – displays or sets network devices
Advantages and disadvantages of using SNMP and WMI polling
After five years of software testing in ByteDance, I was dismissed in December to remind my brother of paddling
VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
What does cardinality mean in set
PHP output (print) log to TXT text
Why can't GC () free memory- Why does gc() not free memory?
Socket, network model notes
Introduction to sap ui5 tools
delphi-UUID
[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)
Go uses channel to control concurrency
Leetcode sword finger offer question brushing - day 27
Research Report on investment share and application prospect of 1,3-propanediol (PDO) industry in the world and China 2022