Center a map marker in Android

前端 未结 3 404
甜味超标
甜味超标 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 12:49

    The correct value for zoom is between 2.0 and 22.00.

    After this you've to add this line

    GoogleMap mMap;
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latlng, 10));
    

    About zoom you can read this from documentation zoom: the desired zoom level, in the range of 2.0 to 21.0. Values below this range are set to 2.0, and values above it are set to 21.0. Increase the value to zoom in. Not all areas have tiles at the largest zoom levels.

    You can check this on http://developer.android.com/reference/com/google/android/gms/maps/CameraUpdateFactory.html

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-11 13:02

    this is because you need to move you camera to the CameraUpdateFactory you created, like this:

    LatLng latLng = new LatLng(Latitude, Longitude);
    map.animateCamera(CameraUpdateFactory.newLatLng(latLng, 11);
    

    if you don't want the animation, then you could just use:

    map.moveCamera(CameraUpdateFactory.newLatLng(latLng, 11);
    
    0 讨论(0)
提交回复
热议问题