preface

In the property management, the staff inspection in the community is still one of the very common work. In order to reduce the investment in the property, the design adopts the scanning two-dimensional code to assist the system to detect the location of each staff inspection, so as to carry out the routine property inspection work. Although QR codes are cheap and easy to use, due to their photo-taking and passive mode, they can lead to cheating problems. Therefore, a positioning function should be added to assist the system in identifying cheating in the routine scanning of codes.

System design

According to the different terminals, the patrol inspection task is divided into two parts, one is realized in the APP, the other is realized in the PC background, and the division of labor is generally as follows:

  • PC: Define and assign patrol tasks. Different personnel assign different patrol tasks. When personnel conduct patrol inspection through the APP, the background can check the completion of the task, confirm that each patrol point has been inspected through the QR code, and replay the track of the patrol task through the location history of the personnel. Since no electronic fences were introduced, cheating could only be determined by human tracking. But the problem of preventing cheating in itself is a deterrent, so it’s not too bad.
  • APP side: personnel can log in through APP, get their inspection tasks after logging in, and scan the code of each inspection point and punch in according to the instructions of inspection. APP starts continuous positioning after opening, and uploads it to the location library at a certain rate.

Because it is applied in the district inspection work, so there is a great requirement for the accuracy of positioning, at least can not deviate too much.

Tencent location service SDK integration

The SDK is integrated under Android

The technology selection is Android positioning SDK and indoor service

1. Unzip the SDK and put the JAR package into Libs first

2. Put SO into JNILIBS

3. Configure project Gradle configuration and module Gradle configuration

google()
jcenter()
 mavenCentral()

Then modify the Gradle configuration

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

4. Give the App corresponding permissions to modify the AndroidManifest.xml file

<? The XML version = "1.0" encoding = "utf-8"? > <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.pms"> <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true" android:theme="@style/Theme.Pms"> <activity android:name=".ui.login.LoginActivity" android:label="@string/title_activity_login"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/app_name"> </activity> <meta-data android:name="TencentMapSDK" Android :value=" your key, your key, This not worthy to get coordinates "/ > < / application > < 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"/> <! - is obtained by GPS precise location - > < USES - permission android: name = "android. Permission. ACCESS_FINE_LOCATION" / > <! - through the network to get a rough location - > < USES - permission android: name = "android. Permission. ACCESS_COARSE_LOCATION" / > <! -- Access the network. Need some location information from a web server - - > < USES - permission android: name = "android. Permission. INTERNET" / > <! -- Access WiFi status. Need WiFi positioning information for network - > < USES - permission android: name = "android. Permission. ACCESS_WIFI_STATE" / > <! -- Modify WiFi state. A WiFi scanning, need WiFi information for network positioning - > < USES - permission android: name = "android. Permission. CHANGE_WIFI_STATE" / > <! -- Access the network state and test the availability of the network. Need information on network operators for network positioning - > < USES - permission android: name = ". Android. Permission ACCESS_NETWORK_STATE "/ > <! - the change of the access network, need some information for network positioning - > < USES - permission android: name = "android. Permission. CHANGE_NETWORK_STATE" / > <! (3) -- To access the current state of the phone, the device ID is required for network positioning --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <! - A - GPS aided positioning support - > < USES - permission android: name = "android. Permission. ACCESS_LOCATION_EXTRA_COMMANDS" / > <! --> <uses-permission android:name="android.permission. Write_external_storage "/> </manifest>

5. Synchronize the next project

Click Sync Project With Gradle Files in the Android Studio Files menu.

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

package com.example.pms; import android.app.Application; 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; import com.tencent.map.geolocation.TencentLocationManager; public class MyApplication extends Application { public static MyApplication app; public static MyApplication getInstance(){ return app; } public TencentLocationManager mLocationManager; @Override public void onCreate() { super.onCreate(); app = this; / / initialization, easy is ~ ~ ~ mLocationManager = TencentLocationManager. GetInstance (this); }}

7. The continuous positioning start is placed in MainActivity

import android.os.Bundle; import android.util.Log; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.tencent.map.geolocation.TencentLocation; import com.tencent.map.geolocation.TencentLocationListener; import com.tencent.map.geolocation.TencentLocationRequest; Public class MainActivity extends AppCompatActivity implements public class MainActivity extends AppCompatActivity implements TencentLocationListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); / / build request TencentLocationRequest request = TencentLocationRequest. The create (); Request.setRequestLevel (tencentLocationRequest.request_level_name); setRequestLevel(tencentLocationRequest.request_level_name); // AllowGPS request.setAllowGPS(true); / / need to open indoor positioning request. SetIndoorLocationMode (true); // Request continuous location, where the default is to push the location information at 10s intervals. MyApplication.getInstance().mLocationManager.requestLocationUpdates(request, this); } @Override 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()); Log.i("location",s); } @Override public void onStatusUpdate(String name, int status, String desc) { // do your work } }

Tencent map track playback

With the support of address, map track playback 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); Var map = new TMap. map ("container", {zoom:12,// Set the map zoom level: center,// Set the map center: center,// Set the map center: mapStyleId: "Style1" // Personalize style}); // Initialize the track map and add it to the map layer new TMap.visualization.Trail({pickStyle:function(item){// return {width: 0; 2}}, startTime: 0, showDuration: }).addTo(map).setData(trailData);}).addTo(map).setData(trailData); // Set data} </script>

Author: webmote

Link: https://webmote.blog.csdn.net…

Source: CSDN

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