javaandroidhuawei-mobile-serviceshuawei-map-kithuawei-location-kit

HMS Map Kit - How to set camera zoom to current location?


I would like to make the map auto-focus to the current location and I've obtained the location via Location Kit.

fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);

Now, I was trying to set the latitude and longitude of the camera in OnMapReady() function, but how to retrieve them?

@Override
public void onMapReady(HuaweiMap huaweiMap) {
    float zoom = 12.0f;
    LatLng latLng = new LatLng(***mLat***, ***mLong***);
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoom);
    .
    .
    .
}

I really need your assistance!!


Solution

  • Update

    There is a official demo show how to realize this:

    use location kit to get the current location

    use map kit to show current location point in map


    You can try to use the function moveCamera or animateCamera to make the map move to the location you want :

    @Override
    public void onMapReady(HuaweiMap huaweiMap) {
        float zoom = 12.0f;
        LatLng latLng = new LatLng(***mLat***, ***mLong***);
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoom);
        huaweiMap.moveCamera(cameraUpdate);        
        
    }