how to get android gps data

android gnss frame

In Android, GPS data is obtained through GNSS location framework, and location is implemented in a hierarchical way, from top to bottom

  • application frame: provider android.location API

Location manager: LocationManager
Location Provider: LocationProvider
Location information: Location
Location Listener: LocationListener

  • Framework Services: the main documents are as follows

frameworks/base/location/java/android/location/*
frameworks/base/services/core/java/com/android/server/location/*
frameworks/base/services/core/java/com/android/server/LocationManagerService.java
frameworks/base/services/core/java/com/android/server/location/GnssLocationProvider.java

  • JNI: Encapsulate GNSS Hal interface (IGnss) to GnssLocationProvider to use

frameworks/base/services/core/jni/com_android_server_location_GnssLocationProvider.cpp

  • HAL layer: Implementation IGnss interface and IGnss service

hardware/libhardware/include/hardware/gps.h

hardware/interfaces/gnss/1.0/ ====>android.hardware.gnss@1.0.so
hardware/interfaces/gnss/1.0/default/ ====>android.hardware.gnss@1.0-impl.so android.hardware.gnss@1.0-service

hardware/interfaces/gnss/1.1/ ====>android.hardware.gnss@1.1.so
hardware/interfaces/gnss/1.1/default/ ====>android.hardware.gnss@1.1-service

gps usage

VIM3 board has integrated USB GPS function on Android 9. It can insert GPS receiver through USB interface, and then install GPS APK, which can view the information of current position, longitude and latitude, or install map software to view positioning

Note

1) It may take a long time to get the first positioning data from the start of GPS module
2) It can also be used without network, but GPS equipment needs to be placed outdoors to receive satellite signals

To use GPS positioning, you need to turn on the location switch in the settings first,Droid Settings > More settings > Device Preferences > Loacation,Location selects on,use command to query location_providers_allowed is gps

1
2
3
130|console:/ $ settings list secure |grep location_providers_allowed          
location_providers_allowed=gps
console:/ $

Apk runs as follows
Image of vim_gps

Android GPS location data API description

Android frameworks encapsulates the standard API to allow applications to obtain GPS related data. For example, longitude and latitude data can be obtained through the methods in the class of frameworks/base/location/java/android/location/Location.java. For details, please refer to the Android source code frameworks/base/tests/LocationTracker, longitude and latitude api are as follows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
583     /**
584 * Get the latitude, in degrees.
585 *
586 * <p>All locations generated by the {@link LocationManager}
587 * will have a valid latitude.
588 */
589 public double getLatitude() {
590 return mLatitude;
591 }


600 /**
601 * Get the longitude, in degrees.
602 *
603 * <p>All locations generated by the {@link LocationManager}
604 * will have a valid longitude.
605 */
606 public double getLongitude() {
607 return mLongitude;
608 }

The longitude and latitude information is provided by GnssLocationProvider as follows

1
2
01-01 13:11:01.483  3735  3757 I GnssLocationProvider: WakeLock released by handleMessage(REPORT_LOCATION, 1, Location[gps 22.570539,113.863433 hAcc=1 et=+6m35s993ms alt=153.4 vel=0.03909778 vAcc=??? sA
cc=??? bAcc=??? {Bundle[{satellites=6, maxCn0=33, meanCn0=22}]}])

22.570539113.863433 represent longitude and latitude data