Without further ado, I will post the code to you directly. The specific code is as follows.
The key code is as follows:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css">html {height:100%;}body {height:100%;margin:0px;padding:0px;}#container {height:50%;}</style> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script src="http://api.map.baidu.com/api?v=1.4" type="text/javascript"></script><script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script> <script>$(function () {navigator.geolocation.getCurrentPosition(translatePoint); //Position});function translatePoint(position) {var currentLat = position.coords.latitude;//Longitude var currentLon = position.coords.longitude;//Latitude var gpsPoint = new BMap.Point(currentLon, currentLat);BMap.Convertor.translate(gpsPoint, 0, initMap); //Convert coordinates}function initMap(point) {//Initialize map map = new BMap.Map("container");//Instance container map.addControl(new BMap.NavigationControl());//Panning zoom control map.addControl(new BMap.ScaleControl());//Scale control map.addControl(new BMap.OverviewMapControl());//Thumbnail map control map.centerAndZoom(point, 15);//Map initialization, parameter map coordinates and levels map.addOverlay(new BMap.Marker(point));//Marker(point));//Sign up the current position var myZoomCtrl = new ZoomControl();map.addControl(myZoomCtrl);function ZoomControl() {this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT; //Adjust the position of the control this.defaultOffset = new BMap.Size(10, 10);//Adjust the position through pixels}//Customize the control, click twice to achieve magnification ZoomControl.prototype = new BMap.Control();ZoomControl.prototype.initialize = function (map) {var div = document.createElement("div");div.appendChild(document.createTextNode("zoomination 2 levels"));div.style.cursor = "pointer";div.style.border = "1px solid gray";div.style.backgroundColor = "white";div.onclick = function (e) {map.zoomTo(map.getZoom() + 2);}map.getContainer().appendChild(div);return div;}}</script> </head> <body> <div id="container"></div></body> </html>