Property inspection of Tencent map anti cheating scenario application


In the property management, the patrol inspection of personnel in the community is still one of the very common work. In order to reduce the investment in the property, the scanning QR code form is designed to assist the system to detect the location of each employee's patrol inspection, so as to carry out the routine property patrol inspection. Although QR code is cheap and easy to use, it will lead to the problem of cheating due to its photographing and passive mode. Therefore, in the conventional code scanning, it is necessary to add the positioning function to assist the system to identify cheating.

System scheme design

The patrol inspection task is divided into two parts according to different ends. One part is implemented in App and the other part is implemented in PC background. The division of labor is as follows:

  • PC side: define and assign patrol inspection tasks, and different personnel assign different patrol inspection tasks. After the personnel conduct patrol inspection through the app, the background can query the completion of the task, determine that each patrol point has been inspected through the QR code, and replay the personnel track of the patrol inspection task through the personnel's position history. Because there is no electronic fence, we can only judge whether to cheat manually according to the track. However, the problem of preventing cheating itself is a deterrent, so the effect will not be too bad.

  • App side: the personnel log in through the app, get their own patrol inspection task after logging in, and scan the code and punch in each patrol inspection point according to the instructions of patrol inspection. After the app is opened, it starts continuous positioning and uploads to the location library at a certain rate.

Because it is used in the patrol inspection of the community, there are still great requirements for the positioning accuracy, at least not too much deviation.

Tencent location service SDK integration

Integrated sdk under Android

Technology selection

Android location SDK

Indoor service

1. Unzip the sdk and put the jar package into libs first

2. Place so to jniLibs

3. Configuration item gradle configuration and module gradle configuration


Then modify the gradle configuration of the module

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

4. Give App corresponding permissions
Modify androidmanifest XML file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

        <meta-data android:name="TencentMapSDK" android:value="Yours key,Yours key,This doesn't deserve to get the coordinate position" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- adopt GPS Get the exact position -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- Get rough location through the network -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <!-- access networks. Some location information needs to be obtained from the network server -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- visit WiFi state. need WiFi Information for network location -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!-- modify WiFi state. launch WiFi scanning, need WiFi Information for network location -->
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <!-- Access network status, Detect network availability. Network operator related information is required for network positioning -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- Changes in access to the network, Some information is needed for network location -->
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <!-- Access the current status of the phone, need device id For network location -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!-- support A-GPS Auxiliary positioning -->
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <!-- be used for log journal -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

5. Synchronize next item

Click Sync Project With Gradle Files in the file menu of Android Studio

6. Customize the Application and add the initialization of location service in it.

package com.example.pms;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.https.HttpsUtils;
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
import com.lzy.okgo.model.HttpHeaders;

public class MyApplication  extends Application {

    public  static  MyApplication  app;

    public  static  MyApplication  getInstance(){
        return  app;

    public TencentLocationManager mLocationManager;

    public void onCreate() {
        app = this;
        //Initialization, easy~~~
        mLocationManager = TencentLocationManager.getInstance(this);

7. Continuous positioning on
Placed in MainActivity

import android.os.Bundle;
import android.util.Log;


//Implement interface definition TencentLocationListener to monitor location information
public class MainActivity extends AppCompatActivity implements TencentLocationListener {

    protected void onCreate(Bundle savedInstanceState) {

        //Build request
        TencentLocationRequest request = TencentLocationRequest.create();
        //We only need latitude and longitude and address name
        request. setRequestLevel(TencentLocationRequest. REQUEST_LEVEL_NAME);
        //Allow GPS
        //Indoor positioning needs to be turned on
        //Request continuous positioning. The default here is to push the position information regularly at an interval of 10s.
        MyApplication.getInstance().mLocationManager.requestLocationUpdates(request, this);

    public void onLocationChanged(TencentLocation location, int error, String reason) {
        // do your work
        String s = String.format("%s %s (%f %f %f)",location.getAddress(),location.getName(),location.getLatitude(),location.getLongitude(),location.getAltitude());

    public void onStatusUpdate(String name, int status, String desc) {
        // do your work


Tencent map track playback

With the support of address, the playback of map track is very easy. Tencent provides dynamic track. You can refer to the following code.

function initMap() {
            var center = new TMap.LatLng(39.984104, 116.307503);

            //Initialize map
            var map = new TMap.Map("container", {
                zoom:12,//Set map zoom level
                center: center,//Set the coordinates of the map center point
                mapStyleId: "style1" //Personalized style
            //Initialize the track graph and add it to the map layer
            new TMap.visualization.Trail({
                pickStyle:function(item){ //Trackgraph style mapping function
                    return {
                        width: 2
                startTime: 0,//The start timestamp of the animation cycle
                showDuration: 120,//Duration of track point highlighting in animation
                playRate:30 // Animation playback speed

            .setData(trailData);//Set data

Author: Webnote


Source: CSDN

The copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.

Added by cpharry on Sat, 19 Feb 2022 22:55:56 +0200