Google会在标记附近映射api v2缩放

Rav*_*avi 17 android android-maps

我在android中使用Google maps api v2.我已经使用纬度和经度放置了一个标记.标记显示在正确的位置,但我希望地图应该只显示标记周围的区域.我想在显示地图时缩放到标记位置,这样它只显示标记的附近区域..任何帮助都将是大.

The*_*ash 62

在您放置标记的此功能中传递当前位置.

private void moveToCurrentLocation(LatLng currentLocation)
{   
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation,15));
    // Zoom in, animating the camera.
    googleMap.animateCamera(CameraUpdateFactory.zoomIn());
    // Zoom out to zoom level 10, animating with a duration of 2 seconds.
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);


}
Run Code Online (Sandbox Code Playgroud)


小智 18

提供标记位置.

private void pointToPosition(LatLng position) {
    //Build camera position
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(position)
            .zoom(17).build();
    //Zoom in and animate the camera.
    mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
Run Code Online (Sandbox Code Playgroud)