Skip to main content

GPS Location Source

The Global Positioning System (GPS) is a satellite-based hyperbolic navigation system.

On Android we don't use pure GPS Location Source, but a combination of many location providers to get the best possible location precision. So we highly recommend using AndroidFusedAdaptiveLocationSource. It will choose the best Location Provider between:

  • Google Fused Location Provider
  • Android System Fused Location Provider
  • Android System GPS Location Provider

Requirements

Check common requirement.

Installation

Check common installation.

Permissions

GPS Location Source requires GPS permission. Declare android.permission.ACCESS_FINE_LOCATION in your app Manifest as follows:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Please request location permission before creating and starting AndroidFusedAdaptiveLocationSource, because without access to it - system can't work.

private val locationPermissionHandler =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
if (!granted) {
// User denied access. show a message explaining how to enable it
return
}
// User granted access. Continue with AndroidFusedAdaptiveLocationSource
}

fun requestLocationPermission() {
// show a model explaining that location access is crucial for localization and navigation.
// then check if it's arealy granted access and request it if not yet
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
// User already granted access, Continue with AndroidFusedAdaptiveLocationSource
} else {
requestLocationPermission.launch(Manifest.permission.ACCESS_FINE_LOCATION)
}
}

Setting Up the AndroidFusedAdaptiveLocationSource

Once you have the MapData, create a AndroidFusedAdaptiveLocationSource instance, then assign it to Map or/and GeoAR as follows:

fun setupLocationSource(mapData: MapData) {
val fusedLocationSource = AndroidFusedAdaptiveLocationSource(requireContext(), mapData)

// assign it to the map if you are using WemapMapSDK
mapView.locationManager.locationSource = fusedLocationSource

// or/and assign it to GeoARView if you are using WemapGeoARSDK
geoARView.locationManager.locationSource = fusedLocationSource
}

Examples

For additional examples and sample implementations of WemapSDKs, visit the official GitHub repository.

Clone the repository and follow the README instructions to run the sample application.