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

前端 未结 5 1204
深忆病人
深忆病人 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

    0 讨论(0)
  • 2021-01-20 01:45

    you can override the map and specific the latitude and longitude and zoom in with suitable for you and disable the gesture of map see this example it is answered before

    limit scrolling and zooming Google Maps Android API v2

    0 讨论(0)
  • 2021-01-20 01:49

    out of the box this is not possible. However what you could theoretically do it find the max bounding box that shows the country in question then everytime the camera moves check to make sure the bounding box is inside the max one. If it is not set it to the max. that would restrict them to a certain spot

    0 讨论(0)
  • 2021-01-20 01:54

    I am pretty sure you cannot only display your chosen country using the google api service. However, what you can do, is restrict google places auto complete to a specific country, by finding your country code (e.g. using this link https://countrycode.org/) and then adding the query to your google places api e.g.

    components=country:your_country_code    //Insert code into example
    

    For example, this is what is would look like:

      https://maps.googleapis.com/maps/api/place/autocomplete/json?
    input=bhubaneshwar&components=country:in&sensor=false&key=your_key
    
    0 讨论(0)
  • 2021-01-20 02:03

    If you are still interested, now it's possible to restrict the user's panning to a given area using the setLatLngBoundsForCameraTarget method.

    You will need to update the dependencies for your Play Services:

    dependencies {
        compile 'com.google.android.gms:play-services:9.6.1'
    }
    
    0 讨论(0)
提交回复
热议问题