当前位置:网站首页>Use of Baidu map
Use of Baidu map
2022-07-02 04:39:00 【Da Da Q】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no">
<title> Browser positioning </title>
<style>
html,body,#allmap{
height: 100%;
width: 100%;
overflow:hidden;
margin:0;
font-family: " Microsoft YaHei ";
}
</style>
<script src="http://api.map.baidu.com/api?v=2.0&ak=0AWEFIYAAjXf0RGWtiEGDXn0H3g3yn51"></script>
</head>
<body>
<div id="allmap"></div>
<script>
// Baidu Maps API function
/* Namespace :API Use BMap As a namespace , All classes are under this namespace .
such as :BMap.Map、BMap.Control、BMap.Overlay.
Map It's a map API The core of the class , Used to instantiate a map .
* Constructors :Map(container,opts) Create a map instance in the specified container .
* Then you need to call Map.centerAndZoom() Method to initialize the map . Uninitialized maps will not be able to do anything .
centerAndZoom(center,zoom) Initialize map
* Be careful :
*1. If center The type is Point when ,zoom Assignment must be made. , Range 3-19 level .
*2. If center When the type is string , such as “ Beijing ”,zoom You can ignore , The map will automatically be based on center Best fit zoom Level .
*/
var map = new BMap.Map("allmap");// Create a map instance
map.centerAndZoom(new BMap.Point(116.404, 39.915),19);// Initialize map : Set the coordinates of the center point and the zoom level
map.enableScrollWheelZoom(true); // Turn on mouse wheel zoom
//Geolocation class : Returns the user's current location .
// This method utilizes the browser's geolocation Interface to get the current location of the user , Unsupported browsers will not be available .
// Constructors : establish Geolocation Object instances
var geolocation = new BMap.Geolocation();
/*Geolocation() Methods of constructors :
getCurrentPosition(): This method will return the current location of the user .
getStatus(): Return status code . The status code returned after successful positioning is :BMAP_STATUS_SUCCESS.
If it is another status code, it means that your current location cannot be obtained .
When the location is successful , The parameters of the callback function are GeolocationResult object , Otherwise null.
GeolocationResult, This category serves as Geolocation Of getCurrentPosition Method , Non instantiable .
GeolocationResult Class has properties :point( Return the result after successful positioning , That is, the coordinate point of the current position )
*/
geolocation.getCurrentPosition(function(result){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
/*Maker Class represents an image annotation on a map .
* Constructors :Maker(point: Point, opts: MarkerOptions) Create an image annotation instance .
*point Parameter specifies the geographic location of the image annotation ;opts Is an optional parameter .*/
var mk = new BMap.Marker(result.point);
/* Core class Map Methods :
addOverlay—— Add an overlay to the map , An instance of an overlay can only be added to the map once
panTo—— Change the center point of the map to the given point .*/
map.addOverlay(mk);
map.panTo(result.point);
/*Point Class represents a geographical coordinate point .
* Constructors :Point(lng,lat) Creates a geographic point coordinate with the specified longitude and latitude .
* This class has two properties :lng Geographic longitude lat Geographical latitude
*/
alert(" The longitude of your current location is :" + result.point.lng + ", Latitude is :" + result.point.lat);
}else{
alert(" seek failed !" + this.getStatus());
}
});
</script>
</body>
</html>
边栏推荐
- A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
- cookie、session、tooken
- Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
- Unity particle Foundation
- Common locks in MySQL
- 洛谷入门3【循环结构】题单题解
- 面试会问的 Promise.all()
- 缓存一致性解决方案——改数据时如何保证缓存和数据库中数据的一致性
- Mysql表insert中文变?号的问题解决办法
- Shutdown procedure after 60
猜你喜欢
Gin framework learning code
How to write a client-side technical solution
Play with concurrency: draw a thread state transition diagram
Vmware安装win10报错:operating system not found
Social media search engine optimization and its importance
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
Thinkphp內核工單系統源碼商業開源版 多用戶+多客服+短信+郵件通知
深圳打造全球“鸿蒙欧拉之城”将加快培育生态,优秀项目最高资助 1000 万元
FAQ | FAQ for building applications for large screen devices
Learn AI safety monitoring project from zero [attach detailed code]
随机推荐
Thinkphp內核工單系統源碼商業開源版 多用戶+多客服+短信+郵件通知
Common sense of cloud server security settings
Free drawing software recommended - draw io
Pytorch---使用Pytorch进行图像定位
二叉树解题(二)
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
面试会问的 Promise.all()
Detailed process of DC-1 range construction and penetration practice (DC range Series)
Yyds dry goods inventory kubernetes introduction foundation pod concept and related operations
One click generation and conversion of markdown directory to word format
UNET deployment based on deepstream
okcc为什么云呼叫中心比传统呼叫中心更好?
powershell_ View PowerShell function source code (environment variable / alias) / take function as parameter
DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
[graduation season · advanced technology Er] young people have dreams, why are they afraid of hesitation
Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
Introduction to JSON usage scenarios and precautions
Wechat applet calculates the distance between the two places
Pytorch---使用Pytorch进行鸟类的预测