Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

WeChat Mini Program Location Permission and uniapp uni.getLocation Implementation

Tech Jul 13 2

Location Permission Setup for WeChat Mini Programs

Access the WeChat Public Platform portal.

  1. Confirm that the mini-program category has been completed. Navigate to the left sidebar, select "Settings" > "Basic Settings" > "Edit".

  2. Under Development Management > Interface Settings > Geolocation, locate the permission toggle: Click the enable button for the required interface (e.g., wx.getLocation). Note that this option will not appear unless the previous step is completed.

  3. Fill out the application form: Submit the necessary documentation including screenshots from a production environment rather than a test setup. Include a brief description of usage, such as:

    The application requires location verification for employee check-in functionality to ensure attendance falls within designated boundaries, supporting remote work operations.

After submission, approval typically takes less than five minutes. Refresh the page manually to verify status.

Using uniapp's uni.getLocation API

Invoke the location service during relevant user interactions, such as when a check-in button is pressed:

uni.getLocation({
  type: 'wgs84',
  success: function(res) {
    console.log("Latitude and longitude retrieved successfully");
    const lat = res.latitude;
    const lng = res.longitude;
    console.log(lat);
    console.log(lng);
  },
  fail: function(res) {
    console.log("Failed to retrieve location");
    console.log(res);
  }
});

Configure the manifest.json file within your uniapp project under the mp-weixin section:

{
  "requiredPrivateInfos": [
    "chooseLocation", "getLocation"
  ],
  "permission": {
    "scope.userLocation": {
      "desc": "Your location is used to verify check-in validity"
    }
  }
}

Both requiredPrivateInfos and permission entries are essential for proper functionality.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.