Search code examples
huawei-mobile-serviceshuawei-developershuawei-map-kithuawei-location-kit

Cannot get com.huawei.hms.location.LocationServices for Huawei Map Kit in android studio


I am currently trying to migrate Google Maps to Huawei map kit in my android project.

It was easy to migrate google maps to Huawei map at first. They are provided all the methods and classes that Google Maps have but now I couldn't get LocationServises class from Huawei that I used in my google maps.

In the documentation they say that Huawei Map kit has com.huawei.hms.location package and LocationServises inside. But why I cannot get it???

The links and libs that I added to gradle below: I refer the Huawei Map Kit documentation

 1. maven {url 'https://developer.huawei.com/repo/'} 

 2. classpath 'com.huawei.agconnect:agcp:1.2.1.301'

 3. maven {url 'https://developer.huawei.com/repo/'} 

 4. implementation 'com.huawei.hms:maps:5.1.0.300'

Solution

  • You can find the location services in the following artifactory

    // Huawei implementation "com.huawei.hms:location:4.0.3.301"

    And retrieve the location with: FusedLocationProviderClient

    Retrieve the last location with the listener

    private var fusedLocationProviderClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context)
    
    fusedLocationProviderClient.lastLocation.addOnSuccessListener { location -> Log.d("Location", location)
    }