Center a map marker in Android

前端 未结 3 416
甜味超标
甜味超标 2021-01-11 12:23

I use the following code to display a single marker at a zoom level but it doesn\'t center tha marker on the map. Only one marker will ever be shown:

LatLng          


        
3条回答
  •  情书的邮戳
    2021-01-11 13:00

    Try the following

    LatLng coordinate = new LatLng(Latitude, Latitude);
    CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 11.0f);
    map.animateCamera(yourLocation);
    

    You could also do this (cleaner way)

    CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(Latitude, Latitude) // Center Set
        .zoom(11.0f)                // Zoom
        .bearing(90)                // Orientation of the camera to east
        .tilt(30)                   // Tilt of the camera to 30 degrees
        .build();                   // Creates a CameraPosition from the builder
    map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    

    From https://developers.google.com/maps/documentation/android/views?hl=fr-FR#moving_the_camera

提交回复
热议问题