当前位置:网站首页>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 …
边栏推荐
- es6总结
- Go h*ck yourself:online reconnaissance (online reconnaissance)
- 【性能測試】一文讀懂Jmeter
- Moher College webmin unauthenticated remote code execution
- Put a lantern on the website during the Lantern Festival
- Relations courantes de la fiche de données d'exploitation pour les activités
- How to set multiple selecteditems on a list box- c#
- deno debugger
- L1-028 judging prime number (10 points)
- C#实现一个万物皆可排序的队列
猜你喜欢
Easy to understand: understand the time series database incluxdb
DM8 uses different databases to archive and recover after multiple failures
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
BUUCTF(4)
Moher college phpMyAdmin background file contains analysis traceability
What does range mean in PHP
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
时序数据库 InfluxDB 2.2 初探
[CV] Wu Enda machine learning course notes | Chapter 9
Thesis learning -- time series similarity query method based on extreme point characteristics
随机推荐
zabbix监控系统部署
Laravel page load problem connection reset - PHP
C#实现一个万物皆可排序的队列
FRP intranet penetration, reverse proxy
es6总结
What does range mean in PHP
deno debugger
zabbix 5.0监控客户端
1、卡尔曼滤波-最佳的线性滤波器
How to get bytes containing null terminators from a string- c#
Convert datetime string to datetime - C in the original time zone
Moher College phpmailer remote command execution vulnerability tracing
Add log file to slim frame - PHP
[Gurobi] 简单模型的建立
PHP converts seconds to timestamps - PHP
Heap concept in JVM
【Go基础】1 - Go Go Go
Cannot click button when method is running - C #
Show server status on Web page (on or off) - PHP
L1-027 rental (20 points)