how to restrict maps to only one country using google maps api for android

前端 未结 5 1215
深忆病人
深忆病人 2021-01-20 01:29

I am totally new to google\'s maps api for android and I was wondering if it is possible to restrict the area the map is showing to one country only. I mean my target users

5条回答
  •  悲哀的现实
    2021-01-20 01:42

    You can restrict the user view to specific square -maybe- of the map, to do so, you can use the following:

    private GoogleMap mMap;
    // Create a LatLngBounds that includes the city of Adelaide in Australia.
    private LatLngBounds ADELAIDE = new LatLngBounds(
      new LatLng(-35.0, 138.58), new LatLng(-34.9, 138.61));
    // Constrain the camera target to the Adelaide bounds.
    mMap.setLatLngBoundsForCameraTarget(ADELAIDE);
    

    in this case, the user will not be able to zoom in, in the map in areas where the camera is totally out of the range -square- you specified.

    for more details, source: https://developers.google.com/maps/documentation/android-api/views#restricting_the_users_panning_to_a_given_area

提交回复
热议问题