Using HBuilder to develop MUI-based H5 + app and using Baidu map positioning function, hbuilderh5

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.