androidgoogle-mapskotlinhuawei-mobile-serviceshuawei-map-kit

Huawei HMS map kit camera won't move/animate to given position


i'm using huawei map kit in my app, i'm following the steps mentioned in their documentation..the map loads and just moves me to ivory coast every time..i don't understand why

my code

private HuaweiMap hMap;
    private MapView mMapView;
    double lat;
    double lng;



    private static final String MAPVIEW_BUNDLE_KEY = "MapViewBundleKey";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        Log.i("TAG", "onCreate");
          Intent i=getIntent();
          double lat=i.getExtras().getDouble("lat");
          double lng=i.getExtras().getDouble("lng");


        mMapView = findViewById(R.id.mapView);

        Bundle mapViewBundle = null;
        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY);
        }

        MapsInitializer.setApiKey("the api key");
        mMapView.onCreate(mapViewBundle);
        //get map instance
        mMapView.getMapAsync(this);


    }

@Override
    public void onMapReady(HuaweiMap map) {

            //get map instance in a callback method
            Log.d("TAG", "onMapReady: ");
            hMap = map;
            hMap.getUiSettings().setZoomControlsEnabled(true);
            hMap.getUiSettings().setZoomGesturesEnabled(true);
            hMap.getUiSettings().setMyLocationButtonEnabled(true); //this button doesn't show on screen either

            LatLng location = new LatLng(lat, lng);
            hMap.addMarker(new MarkerOptions().position(location));
            CameraPosition cameraPosition = new CameraPosition(location,8,2.2f,31.5f);
            hMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
            hMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    }

i'm using google maps in the same app (for phones that use gms) and using almost the same approach and everything works perfectly fine with the google map.. please help


Solution

  • Question 1:

    hMap.getUiSettings().setMyLocationButtonEnabled(true) does not take effect.

    Before using hMap.getUiSettings().setMyLocationButtonEnabled(true), you need to use hMap.setMyLocationEnabled(true) to enable the location function on the map.

    If setMyLocationEnabled is set to false, the my-location icon will not be displayed and the location function is unavailable regardless of whether setMyLocationButtonEnabled is set. Therefore, you are advised to use hMap.setMyLocationEnabled(true) to display the my-location icon.

    For more information, please refer to docs.

    Question 2:

    The map camera always moves to Ivory Coast.

    Your usage is correct. You are advised to print relevant longitudes and latitudes to see if they remain unchanged.

    In addition, the moveCamera class is used to directly move the camera, and the animateCamera class is used to move the camera through animation. You can use either of the classes to move the camera.