How to use Baidu map api_javascript skills
If you want to use the Baidu Map API, you first need to obtain a Baidu Map API key, and then introduce the Baidu Map API. Next, we will introduce in detail the techniques for obtaining and introducing the API key, and provide you with the code For a detailed explanation of how to use Baidu Maps API, please see below.
First of all, if you want to call Baidu Maps API, you need to obtain a Baidu Maps API key.
Applying for a key is very simple. There are relevant links on the homepage of Baidu Maps API. Fill in the relevant information and Baidu will give you a key.
The next step is to introduce Baidu Maps API
The key code is as follows:
Next we can create a map and try it out. (Js code)
var map = new BMap.Map("container"); // Create a map instance
var point = new BMap.Point(120.391655,36.067588); // Create point coordinates
map.centerAndZoom(point, 15);
//map.centerAndZoom("Beijing", 15);
//map.centerAndZoom("Hongkong", 15);
Three points need to be explained here: 1.map.centerAndZoom method creates a map. The first parameter can be to create a map based on a previously created point as the center, or to create a map based on the Chinese name of a city area. (If spelled correctly, it can be created based on the English name of the city)
2. The second parameter of map.centerAndZoom is the map zoom level, the maximum is 19 and the minimum is 0. (But actually when it is reduced to 3...)
About map size:
Can be passed
You can also set it
Baidu Map provides a very rich functional space for us to use.
1.Control: The abstract base class of the control. All controls inherit the methods and properties of this class. This class allows you to implement custom controls.
2.NavigationControl: Map pan and zoom control, which is located in the upper left corner of the map by default on PC. It includes the function of controlling the pan and zoom of the map. The mobile version provides a zoom control, which is located at the bottom right of the map by default.
3.OverviewMapControl: Thumbnail map control, located at the bottom right of the map by default, is a foldable thumbnail map.
4.ScaleControl: Scale control, located at the bottom left of the map by default, displays the scale relationship of the map.
5.MapTypeControl: Map type control, located in the upper right corner of the map by default (map, satellite, 3D).
6.CopyrightControl: Copyright control, located at the bottom left of the map by default.
7.GeolocationControl: Positioning control, developed for mobile terminals, located at the bottom left of the map by default.
Rendering
map.addControl(new BMap.ScaleControl()); //Scale
map.addControl(new BMap.OverviewMapControl());//Thumbnail
map.addControl(new BMap.MapTypeControl()); //Map type
map.setCurrentCity("Qingdao");
Note: The switching function of MapTypeControl is only available when city information is set
Map event:
Most objects in the Baidu Map API contain the addEventListener method, through which we can listen to object events.
Example:
map.addEventListener("click", function(){
alert("You clicked on the map.");
});
When we no longer want to listen to events, we can remove the event listener. Each API object provides removeEventListener to remove event listening functions.
map.removeEventListener("click", functionA);
map.addEventListener("click", functionA);
Map cover:
Overlay: The abstract base class of overlays. All overlays inherit the methods of this class.
Marker: Marker represents a point on the map, and the mark icon can be customized.
Label: Represents a text label on the map. You can customize the text content of the label.
Polyline: Represents a polyline on the map.
Polygon: Represents a polygon on the map. A polygon is similar to a closed polyline, but you can also add a fill color to it.
Circle: Represents a circle on the map.
InfoWindow: The information window is also a special overlay that can display richer text and multimedia information. Note: Only one information window can be open on the map at the same time.
Annotation example:
var point = new BMap.Point(120.389472,36.072362);//默认 可以通过Icon类来指定自定义图标 var marker = new BMap.Marker(point); var label = new BMap.Label("青岛市政府",{offset:new BMap.Size(20,-10)});//标注标签 marker.setLabel(label)//设置标注说明 marker.enableDragging();//标注可以拖动的 marker.addEventListener("dragend", function(e){ alert(e.point.lng + ", " + e.point.lat);//打印拖动结束坐标 }); map.addOverlay(marker); var point = new BMap.Point(120.387244,36.064835); var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25)); var marker2 = new BMap.Marker(point, {icon: myIcon}); map.addOverlay(marker2); var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>详细信息</p>"); //弹出窗口 marker2.addEventListener("click", function(){ this.openInfoWindow(infoWindow); });
The above description is the entire content of this article. I hope it will be helpful to everyone using Baidu Map API.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Python to call Baidu Map API to implement geographical location query function? With the development of the Internet, the acquisition and utilization of geographical location information is becoming more and more important. Baidu Maps is a very common and practical map application that provides a wealth of geographical location query services. This article will introduce how to use Python to call Baidu Map API to implement the geographical location query function, and attach a code example. Apply for a Baidu Map developer account and application First, you need to have a Baidu Map developer account and create an application. Log in

Python programming practice: How to use Baidu Map API to generate static map functions Introduction: In modern society, maps have become an indispensable part of people's lives. When working with maps, we often need to obtain a static map of a specific area for display on a web page, mobile app, or report. This article will introduce how to use the Python programming language and Baidu Map API to generate static maps, and provide relevant code examples. 1. Preparation work To realize the function of generating static maps using Baidu Map API, I

Python programming to analyze the coordinate conversion function in Baidu Map API document Introduction: With the rapid development of the Internet, the map positioning function has become an indispensable part of modern people's lives. As one of the most popular map services in China, Baidu Maps provides a series of APIs for developers to use. This article will use Python programming to analyze the coordinate conversion function in Baidu Map API documentation and give corresponding code examples. 1. Introduction In development, we sometimes involve coordinate conversion issues. Baidu Map AP

Detailed steps for using Python and Baidu Map API to implement route planning and real-time traffic query functions 1. Introduction With the development of cities, traffic is becoming increasingly congested. People need to plan their routes reasonably to avoid congested sections when traveling, and they also hope to obtain real-time traffic information. Traffic information. Baidu Maps provides a powerful route planning and real-time traffic query API, which we can call using the Python programming language to implement route planning and real-time traffic query functions. This article will introduce in detail how to use Python and Baidu Map A

Python programming tutorial: Using Baidu Map API to implement comprehensive functions of path planning and traffic situation Introduction: With the rapid development of intelligent transportation, our demand for path planning and traffic situation is getting higher and higher. The API interface provided by Baidu Map provides convenience for us to implement these functions. This tutorial will lead you to use the Python programming language to realize the comprehensive functions of route planning and traffic situation by calling Baidu Map API. Preface: Before we start writing code, we need to prepare some necessary tools. first

How to call Baidu Map API through Python programming to implement map display function? With the rapid development of the Internet, map applications have become an indispensable part of our lives. As one of the largest map applications in China, Baidu Maps provides us with a wealth of services and API interfaces, which can easily realize the map display function. This article will introduce how to call Baidu Map API through Python programming to realize the map display function, and give corresponding code examples. First, we need to register a

How to use Python and Baidu Map API to obtain POI points in a specific administrative area? Geographic information and location data play an increasingly important role in modern society. Obtaining POI (points of interest) information in a specific administrative area can provide a lot of help for various application scenarios. This article will introduce how to use the Python programming language and Baidu Map API to obtain POI points within a specific administrative area. Before we get started, we need to prepare some tools and resources. First, we need a Baidu Maps developer account and

Python programming skills: How to obtain POI points within a geo-fence based on Baidu Map API Length: 1500 words 1. Introduction With the development of mobile Internet, geographical location information plays an important role in many application scenarios. Baidu Map API provides powerful functions that allow us to obtain nearby POI points according to specific needs. This article will introduce how to use Baidu Map API to obtain POI points within the geofence range, and implement it through Python programming. 2. Preparation before starting programming
