justin
justin

Reputation: 31

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

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

Upvotes: 3

Views: 4455

Answers (2)

bikram
bikram

Reputation: 7935

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);
}

Upvotes: 3

KENdi
KENdi

Reputation: 7741

To show only specific area or region then you can use Polygons.

Polygon objects are similar to Polyline objects in that they consist of a series of coordinates in an ordered sequence. However, instead of being open-ended, polygons are designed to define regions within a closed loop with the interior filled in.

You can add a Polygon to the map in the same way as you add a Polyline. First create a PolygonOptions object and add some points to it. These points will form the outline of the polygon. You then add the polygon to the map by calling GoogleMap.addPolygon(PolygonOptions) which will return a Polygon object.

Visit this page on how to use Polygon.

Upvotes: 0

Related Questions