3

Preface

In property management, personnel inspections in the community are still one of the very common tasks. In order to reduce the investment in the property, a scanning QR code is designed to assist the system to detect the location of each employee's inspection to facilitate regular property inspections. Inspection work. Although the two-dimensional code is cheap and easy to use, it can cause cheating due to its photo-capable and passive mode. Therefore, in the conventional scanning code, a positioning function needs to be added to assist the system in identifying cheating behaviors.

Systematic design

The inspection task is divided into two parts according to the different terminals, one part is implemented in the App, and the other part is implemented in the PC background. The division of labor is roughly as follows:

  • PC: Define and assign inspection tasks, and different personnel are assigned different inspection tasks. After the personnel conduct inspections through the app, the background can query the completion of the task, confirm that each inspection point has been inspected through the QR code, and playback the personnel track of the inspection task through the personnel's location history. Because no electronic fence was introduced, it was only possible to manually judge whether or not to cheat according to the trajectory. However, the problem of preventing cheating itself is a kind of deterrence, so the effect is not too bad.
  • App side: personnel log in through the app, get their own patrol tasks after logging in, and follow the patrol instructions to scan codes and punch cards at each patrol point. After the app is opened, continuous positioning is enabled and uploaded to the location library at a certain rate.

image.png

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

Tencent location service SDK integration

Integrated SDK under Android

The technical selection is Android positioning SDK and indoor service

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

image.png

2. Place so to jniLibs

image.png

3. Configure project gradle configuration and module gradle configuration

google()
jcenter()
 mavenCentral()

image.png

Then modify the module gradle configuration

image.png

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

4. Give the App the appropriate permissions
Modify the AndroidManifest.xml file

<?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="你的key,你的key,这个不配获取不了坐标位置" />
    </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"/>
    <!-- 通过GPS得到精确位置 -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- 通过网络得到粗略位置 -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <!-- 访问网络. 某些位置信息需要从网络服务器获取 -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- 访问WiFi状态. 需要WiFi信息用于网络定位 -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!-- 修改WiFi状态. 发起WiFi扫描, 需要WiFi信息用于网络定位 -->
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <!-- 访问网络状态, 检测网络的可用性. 需要网络运营商相关信息用于网络定位 -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- 访问网络的变化, 需要某些信息用于网络定位 -->
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <!-- 访问手机当前状态, 需要device id用于网络定位 -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <!-- 支持A-GPS辅助定位 -->
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <!-- 用于 log 日志 -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

5. Synchronize the project

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

6. Customize the Application and add the initialization of the location service 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;
        //初始化,easy的很~~~
        mLocationManager = TencentLocationManager.getInstance(this);
    }
}

7. Continuous positioning on
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;

//实现接口定义 TencentLocationListener 监控位置信息
public class MainActivity extends AppCompatActivity implements TencentLocationListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);       

        //建立请求
        TencentLocationRequest request = TencentLocationRequest.create();
        //我们只需要经纬度和地址名称
        request. setRequestLevel(TencentLocationRequest. REQUEST_LEVEL_NAME);
        //允许使用GPS
        request.setAllowGPS(true);
        //需要开启室内定位
        request.setIndoorLocationMode(true);
        //请求连续定位,这里默认是10s间隔定时推送位置信息。
        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 trajectory playback

With the support of the address, the map track playback is very easy. Tencent provides a 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,//设置地图缩放级别
                center: center,//设置地图中心点坐标
                mapStyleId: "style1" //个性化样式
            });
            //初始化轨迹图并添加至map图层
            new TMap.visualization.Trail({
                pickStyle:function(item){ //轨迹图样式映射函数
                    return {
                        width: 2
                    }
                },
                startTime: 0,//动画循环周期的起始时间戳
                showDuration: 120,//动画中轨迹点高亮的持续时间
                playRate:30 // 动画播放倍速

            })
            .addTo(map)
            .setData(trailData);//设置数据
        }
    </script>

image.png

Author: webmote

Link: https://webmote.blog.csdn.net/article/details/111352712

Source: CSDN

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


腾讯位置服务
1.7k 声望132 粉丝

立足生态,连接未来