Github

Method of use

1. Add permissions to the manifest file (you don’t need to add permissions to the manifest file)

defaultConfig { ..... Manifestplaceholder = [AMAP_KEY: "How you apply for Autorama Key"].... } dependencies{ ... Implementation 'com. Making. Theoneee: TheLocation: 2.1.0'... }Copy the code

Obtain Key of Autonavi map

2. The initialization

private var mLocationManager: TheLocationManager? = null mLocationManager = TheLocationManager.getInstance()? .init(this, this) #init (context: context, listener: AMapLocationListener, options) AMapLocationClientOption? = null )Copy the code

3. Start positioning (Dynamically apply for permission before using it)

mLocationManager? .start()Copy the code

4. Locate the callback process

    override fun onLocationChanged(location: AMapLocation?) {
        ....
        mLocationManager?.stop()
        location?.let {
            mViewModel.address.set(it.getLog())
        }
        ...
    }
    
Copy the code

5. Release

override fun onDestroy() { super.onDestroy() mLocationManager? .release() }Copy the code

Complete sample code

Framework used in the Demo

TheCore-MVVM

TheBase-MVVM

TheCommon