当前位置:网站首页>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>边栏推荐
- Unity particle Foundation
- Pytoch --- use pytoch to predict birds
- MySQL table insert Chinese change? Solution to the problem of No
- [C language] Dynamic Planning --- from entry to standing up
- 深圳打造全球“鸿蒙欧拉之城”将加快培育生态,优秀项目最高资助 1000 万元
- idea自動導包和自動删包設置
- Thinkphp內核工單系統源碼商業開源版 多用戶+多客服+短信+郵件通知
- Recyclerview add header
- Wechat applet calculates the distance between the two places
- Flag bits in assembly language: CF, PF, AF, ZF, SF, TF, if, DF, of
猜你喜欢

Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data

One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
![[C language] basic learning notes](/img/d2/1aeb2d37d97b9cfe4b21aa3ac37645.png)
[C language] basic learning notes

Pytoch --- use pytoch for image positioning

Landing guide for "prohibit using select * as query field list"

Idea automatic package import and automatic package deletion settings

How to modify data file path in DM database

June book news | 9 new books are listed, with a strong lineup and eyes closed!

Play with concurrency: draw a thread state transition diagram

How to write a client-side technical solution
随机推荐
C - derived classes and constructors
Thinkphp6 limit interface access frequency
Recyclerview add header
【毕业季·进击的技术er】年少有梦,何惧彷徨
Binary tree problem solving (1)
office_ Delete the last page of word (the seemingly blank page)
Research on the security of ognl and El expressions and memory horse
Online incremental migration of DM database
Ognl和EL表达式以及内存马的安全研究
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
记录一次Unity 2020.3.31f1的bug
Summary of common string processing functions in C language
geotrust ov多域名ssl证书一年两千一百元包含几个域名?
Pytorch---使用Pytorch进行鸟类的预测
Pytoch --- use pytoch to predict birds
Pytoch --- use pytoch to realize u-net semantic segmentation
6月书讯 | 9本新书上市,阵容强大,闭眼入!
万卷共知,一书一页总关情,TVP读书会带你突围阅读迷障!
LeetCode-归并排序链表
Free drawing software recommended - draw io