1

In my application used Google Maps V2. Here's the code fragment, which describes the map fragment.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/g_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <ImageView
        android:id="@+id/center_button"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/btn_centering"
        android:clickable="true" />

</RelativeLayout>

How can I limit the rectangular area of ​​the map on which the user can navigate? I tried to do this with the OnCameraChangeListener, but it looked ugly and unstable. (Perhaps this is my fault)))

Alex Sh
  • 131
  • 1
  • 3
  • 10

3 Answers3

2

You can do it so:

// Create a LatLngBounds that includes the city of Adelaide in Australia.
final 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);
Community
  • 1
  • 1
mohax
  • 4,435
  • 2
  • 38
  • 85
0

I found this in the documentation pageof the google maps API, but I don't know if this is what you want:

private GoogleMap mMap;
// Create a LatLngBounds that includes Australia.
private LatLngBounds AUSTRALIA = new LatLngBounds(
  new LatLng(-44, 113), new LatLng(-10, 154));

// Set the camera to the greatest possible zoom level that includes the
// bounds
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(AUSTRALIA, 0));
Alejandro Cumpa
  • 2,118
  • 1
  • 24
  • 45
  • 1
    This is not what I'm looking for. For example, the user could navigate only in the map of Australia's Capability exit this bounds (LatLngBounds AUSTRALIA). – Alex Sh Jan 15 '14 at 15:21
  • 1
    I found [this](http://stackoverflow.com/questions/14977078/limit-scrolling-and-zooming-google-maps-android-api-v2), maybe can give you an idea. I think you're on the right way, but maybe your method is the issue. – Alejandro Cumpa Jan 15 '14 at 15:38
0

Have a look over https://stackoverflow.com/a/48473495/6117565. For any rectangular area you must know lat and long for corners. Thats all.

bikram
  • 7,127
  • 2
  • 51
  • 63