Not receiving user location

Hi there,

We’ve got the map spun up, following the available tutorials but can’t seem to get the user location to work.

Code in MainActivity.kt:

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.tomtom.sdk.location.android.AndroidLocationEngine
import com.tomtom.sdk.maps.display.MapOptions
import com.tomtom.sdk.maps.display.TomTomMap
import com.tomtom.sdk.maps.display.location.LocationMarkerOptions
import com.tomtom.sdk.maps.display.location.LocationMarkerType
import com.tomtom.sdk.maps.display.ui.MapFragment


class MainActivity : AppCompatActivity() {

    private lateinit var locationEngine: AndroidLocationEngine
    private lateinit var tomTomMap: TomTomMap
    private val APIKEY= "<HIDDEN_FOR_DEMO_PURPOSES>"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val mapOptions = MapOptions(mapKey = APIKEY )

        val mapFragment = MapFragment.newInstance(mapOptions)
        supportFragmentManager.beginTransaction()
            .replace(R.id.map_container, mapFragment)
            .commit()

        // Location Engine
        locationEngine = AndroidLocationEngine(context = this)
        locationEngine.enable()

        mapFragment.getMapAsync { map ->
            tomTomMap = map
            enableUserLocation()
        }
    }

    private fun enableUserLocation() {
        // Getting locations to the map
        tomTomMap.setLocationEngine(locationEngine)
        val locationMarker = LocationMarkerOptions(type=LocationMarkerType.POINTER)
        tomTomMap.enableLocationMarker(locationMarker)
    }
} 

With the above we’re expecting to see a small user location indicator. Tested on physical devices as well as emulators.

Anyone know what we’re missing?

Just covering the basics:

  • API Key hidden for screen shot purposes.
  • We’ve added in the needed dependencies and such and are getting the app to build and display the map.
  • Just can’t seem to get the user location to display for some reason…

Hello,
From an API perspective, in snippets, everything looks fine to me. But the question is, are the location permissions handled correctly? We can’t see any code related to this in provided snippets.

Thanks for the response Tom.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.navigation">

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

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Navigation"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>

The above is in the AndroidManifest.xml

The app has manually been given permissions (click-hold → app info → permissions → locations → granted for course and fine)

Is there another spot that permissions need to be set up for this to work?

Hi,
We tried to replicate your issue, but after building an app according to your snippets it works fine for us.
We used these dependencies:

implementation "com.tomtom.sdk:maps-display:0.3.782"
implementation "com.tomtom.sdk:location-android:0.3.782"