How to show only a specific region/area in google map for android api v2 [Android]

Viewed 3433

How to show only a specific region/area in google map for android api v2?.all functionalities must be available in that region like zooming,dragging etc. the all other areas must be cropped off or invisible. Is that possible??? I am using eclipse.help me please

2 Answers

This trick worked for me

  @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    //get latlong for corners for specified place
    LatLng one = new LatLng(27.700769, 85.300140);
    LatLng two = new LatLng(27.800769, 85.400140);

    LatLngBounds.Builder builder = new LatLngBounds.Builder();

    //add them to builder
    builder.include(one);
    builder.include(two);

    LatLngBounds bounds = builder.build();

    //get width and height to current display screen
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;

    // 20% padding
    int padding = (int) (width * 0.20);

    //set latlong bounds
    mMap.setLatLngBoundsForCameraTarget(bounds);

    //move camera to fill the bound to screen
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));

    //set zoom to level to current so that you won't be able to zoom out viz. move outside bounds
    mMap.setMinZoomPreference(mMap.getCameraPosition().zoom);
}
Related