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

北城以北 提交于 2019-12-11 01:03:22

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/35864606/how-to-show-only-a-specific-region-area-in-google-map-for-android-api-v2-androi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!