Using HBuilder to develop MUI-based H5 + app and using Baidu map positioning function, hbuilderh5
There are two methods for locating:
First, you must initialize the built-in map:
Var map = new plus. maps. Map ("map ");
Here, the yellow map is the id in html:
<Div id = "map"> loading a map... </div>
1. Call the GPS Positioning API (note that the baidu and bd09ll parameters are used, and coordinates do not need to be converted)
1 plus.geolocation.getCurrentPosition(function(p) { 2 console.log(p.addresses); 3 console.log( p.coords.longitude); 4 console.log( p.coords.latitude); 5 var gpsPoint = new plus.maps.Point( p.coords.longitude, p.coords.latitude); 6 map.centerAndZoom(gpsPoint, 19); 7 8 }, function(e) {}, { 9 provider: 'baidu', coordsType: 'bd09ll' });
2. Use h5 + Built-in map for positioning.
Map. getUserLocation (function (state, pos) {console. log (JSON. stringify (pos); if (0 = state) {map. centerAndZoom (pos, 16); plus. maps. map. reverseGeocode (pos, {}, function (event) {var address = event. address; // The converted geographic location var point = event. coord; // The converted coordinate information var coordType = event. coordType; // The converted coordinate system type alert ("Address:" + address); console. log (JSON. stringify (point); console. log (coordType) ;}, function (e) {alert ("Failed:" + JSON. stringify (e ));});}});
Scan the attention and learn programming together: