当前位置:网站首页>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 …
边栏推荐
猜你喜欢
What does range mean in PHP
This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
[CV] Wu Enda machine learning course notes | Chapter 9
Conversion of yolov5 XML dataset to VOC dataset
1. Getting started with QT
时序数据库 InfluxDB 2.2 初探
小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
Fault analysis | MySQL: unique key constraint failure
zabbix监控系统自定义监控内容
随机推荐
DM8 uses different databases to archive and recover after multiple failures
[untitled] 2022 polymerization process analysis and polymerization process simulation examination
deno debugger
弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
21个战略性目标实例,推动你的公司快速发展
The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)
ES6 summary
论文学习——基于极值点特征的时间序列相似性查询方法
Div hidden in IE 67 shows blank problem IE 8 is normal
This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
Set and modify the page address bar icon favicon ico
How to reset IntelliSense in vs Code- How to reset intellisense in VS Code?
Introduction to neural network (Part 2)
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
Oracle-存储过程与函数
广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
L1-024 the day after tomorrow (5 points)
Thesis learning -- time series similarity query method based on extreme point characteristics
[test de performance] lire jmeter
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)