当前位置:网站首页>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 …
边栏推荐
- PHP converts seconds to timestamps - PHP
- ES6 summary
- 力扣今日题-1200. 最小绝对差
- Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
- 2022 electrician (intermediate) examination question bank and electrician (intermediate) examination questions and analysis
- L1-024 the day after tomorrow (5 points)
- 一文了解數據异常值檢測方法
- deno debugger
- Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
- How to reset IntelliSense in vs Code- How to reset intellisense in VS Code?
猜你喜欢
Collections in Scala
[gurobi] establishment of simple model
PCIE知识点-010:PCIE 热插拔资料从哪获取
Linear algebra 1.1
DM8 command line installation and database creation
Unity-Text上标平方表示形式+text判断文本是否为空
Thesis learning -- time series similarity query method based on extreme point characteristics
Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
ZABBIX monitoring system custom monitoring content
What sparks can applet container technology collide with IOT
随机推荐
Leetcode 146. LRU 缓存
Activiti常见操作数据表关系
墨者学院-Webmin未经身份验证的远程代码执行
Chrome is set to pure black
1. Qt入门
Show server status on Web page (on or off) - PHP
墨者学院-PHPMailer远程命令执行漏洞溯源
deno debugger
Devops Practice Guide - reading notes (long text alarm)
The right way to capture assertion failures in NUnit - C #
1. Getting started with QT
Oracle stored procedures and functions
Leetcode 23. 合并K个升序链表
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-...)
How to use C language code to realize the addition and subtraction of complex numbers and output structure
一文了解數據异常值檢測方法
Thesis learning -- time series similarity query method based on extreme point characteristics
Unity write word
Put a lantern on the website during the Lantern Festival
Wechat has new functions, and the test is started again