Web development practices on WeChat public platform-3. Use JSSDK to obtain the geographical location (HTML5 + jQuery) and jssdkhtml5

Source: Internet
Author: User

Public platform Web development practices-3. Use JSSDK to obtain geographical locations (HTML5 + jQuery) and jssdkhtml5

Copy A jssdkenvironment and create an index.html file. The structure is 7.1.

 

Figure 7.1 file structure

In location. js, encapsulate the "getLocation" interface as follows:

 

01wxJSSDK. location = function (locationApi) {02 if (wxJSSDK. isReady) {// wxJSSDK. isReady check whether JSSDK Initialization is complete 03 if (locationApi) {04 locationApi. getLocation & wx. getLocation ({// obtain the geographic location interface 05 success: function (res) {06 locationApi. getLocation. success & 07locationApi. getLocation. success (res); 08} 09}); 10} else {11 console. log ("configuration parameters missing"); 12} 13} else {14 console. log ("sorry, wx has not been initialized. Please wait until the wx Initialization is complete, and then call the location interface server 15. "); 16} 17}

In the index.html file, add the "get location" button and display the obtained location information. The code structure is as follows:

 

01 <! DOCTYPE html> 02 

  

Remember to add the "getLocation" API permission in the JSSDK configuration environment.

[Code description]

After the location of "getLocation" is successful, information about "latitude", "longitude", "Speed", and "location accuracy" will be returned. After you click "Get location", a message is displayed, as shown in Figure 7.2. The result 7.3 is displayed after the location service is obtained successfully.

Figure 7.2 JSSDK location information prompt

Figure 7.3 successful location service information

Public platform Web development practices-HTML5 + JSSDK hybrid development and decryption

 

Welcome to share this book

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.