We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesMap KitAndroidEnhanced SDKLocation Display

Location Display

The enhanced Map SDK for Android provides the native location capabilities. To use the high-precision location capability, perform the following steps to configure the location source for high-precision location.

Before turning on the location display switch, you need to set a location source (LocationSource) which can provide a display position for the location.

  1. Implement LocationSource.
    The sample code is as follows:
    Java
    Kotlin
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. private LocationSource.OnLocationChangedListener mLocationChangedListener;
    2. LocationSource hwLocationSource = new LocationSource() {
    3. @Override
    4. public void activate(LocationSource.OnLocationChangedListener listener) {
    5. mLocationChangedListener = listener;
    6. }
    7. @Override
    8. public void deactivate() {
    9. mLocationChangedListener = null;
    10. }
    11. };
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. var mLocationChangedListener: LocationSource.OnLocationChangedListener? = null
    2. var hwLocationSource: LocationSource = object : LocationSource {
    3. override fun activate(listener: LocationSource.OnLocationChangedListener) {
    4. mLocationChangedListener = listener
    5. }
    6. override fun deactivate() {
    7. mLocationChangedListener = null
    8. }
    9. }
  2. Set the location source and turn on the location display switch.
    The sample code is as follows:
    Java
    Kotlin
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. hwMap.setLocationSource(hwLocationSource);
    2. hwMap.setMyLocationEnabled(true);
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. hMap.setLocationSource(hwLocationSource)
    2. hMap.isMyLocationEnabled = true
Search in Guides
Enter a keyword.