当前位置:网站首页>Call Baidu map to display the current position
Call Baidu map to display the current position
2022-07-04 08:14:00 【Xiao Xia Mu】
Get Baidu key

Be careful :JavaScript API Only browser type ak, Please apply at ak Pay attention to choose .
Apply for Baidu key link :http://lbsyun.baidu.com/apiconsole/key?application=keyImplementation code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
<title>Geolocation</title>
<style type="text/css"> html {
height: 100% } body {
height: 100%; margin: 0px; padding: 0px; } #container {
width: 70%; height: 100%; margin: 20px auto; } </style>
</head>
<body>
<div id="container"></div>
<!-- Load Baidu map api-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak= Your key "></script>
<script> // Check whether the browser supports positioning API if (navigator.geolocation) {
// getCurrentPosition Method to get the coordinate value of the current position navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude; // latitude var longitude = position.coords.longitude; // longitude console.log(" longitude :" + longitude + " latitude :" + latitude); // container Indicates which container to inject var map = new BMap.Map("container"); // Pass the longitude and latitude to Baidu var point = new BMap.Point(longitude, latitude); /// Initialize map , Set center point coordinates and map level map.centerAndZoom(point, 15); // Coordinate transformation var convertor = new BMap.Convertor(); var pointArr = []; pointArr.push(point); convertor.translate(pointArr, 1, 5, translateCallback); // Callback function after coordinate conversion function translateCallback(data) {
if (data.status === 0) {
// Create annotations var marker = new BMap.Marker(data.points[0] map.addOverlay(marker); map.setCenter(data.points[0]); } } }, function(error) {
console.log(error.code) }) } </script>
</body>
</html>
According to the effect :
3. At present, there are mainly three coordinate systems in China :
- WGS84: For a geodetic coordinate system , It is also widely used at present GPS The coordinate system used by GPS .
- GCJ02: Also known as the Mars coordinate system , It is the coordinate system of geographic information system developed by China National Bureau of Surveying and mapping . from WGS84 The encrypted coordinate system .
- BD09: For Baidu coordinate system , stay GCJ02 The coordinate system is encrypted again . among bd09ll Represents Baidu latitude and longitude coordinates ,bd09mc Represents Baidu Mercator metric coordinates . Map of non China area , Unified use of service coordinates WGS84 coordinate .
Baidu external interface coordinate system is BD09 Coordinate system , Not at all GPS The true latitude and longitude of the acquisition , Using Baidu map JavaScript API Before service , Need to convert non Baidu coordinates into Baidu coordinates through coordinate conversion interface first .
Welcome to read , I have limited experience , There are some mistakes or omissions in the blog writing , I hope you can give me some advice , Thank you so much . Article in continuous update …
边栏推荐
- zabbix监控系统部署
- 1. Qt入门
- Difference between static method and non static method (advantages / disadvantages)
- The text box displays the word (prompt text) by default, and the text disappears after clicking.
- Unity-写入Word
- [go basics] 1 - go go
- Sort by item from the list within the list - C #
- Div hidden in IE 67 shows blank problem IE 8 is normal
- Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
- Using the rate package for data mining
猜你喜欢

Mouse over to change the transparency of web page image

Moher College phpmailer remote command execution vulnerability tracing

深入浅出:了解时序数据库 InfluxDB

Easy to understand: understand the time series database incluxdb

DM8 database recovery based on point in time

一文了解数据异常值检测方法

Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)

PCIe knowledge points -010: where to get PCIe hot plug data

AcWing 244. Enigmatic cow (tree array + binary search)

ZABBIX 5.0 monitoring client
随机推荐
JVM -- class loading process and runtime data area
How to write a summary of the work to promote the implementation of OKR?
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
Technology sharing | MySQL parallel DDL
L1-028 judging prime number (10 points)
C # implements a queue in which everything can be sorted
WordPress get_ Users() returns all users with comparison queries - PHP
Flask 常用组件
BUUCTF(4)
Example analysis of C # read / write lock
zabbix监控系统部署
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
Use preg_ Match extracts the string into the array between: & | people PHP
时序数据库 InfluxDB 2.2 初探
OKR vs. KPI 一次搞清楚这两大概念!
团体程序设计天梯赛-练习集 L2-002 链表去重
【性能测试】一文读懂Jmeter
Redis 哨兵机制
Go h*ck yourself:online reconnaissance (online reconnaissance)
Linear algebra 1.1