2014-01-15 72 views
1

在我的應用程序中使用Google Maps V2。 這是代碼片段,它描述了地圖片段。限制矩形區域,Google Maps V2

<?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> 

如何限制用戶可以導航的地圖的矩形區域?我試圖用OnCameraChangeListener做到這一點,但它看起來很醜並且不穩定。 (也許這是我的錯)))

+0

您的意思是用戶只能在某個地理區域導航? – Aiapaec

+1

@El_Mochiq,是的,只能在由矩形包圍的區域內導航。 –

回答

0

我發現這個pageof谷歌地圖API的文檔中,但我不知道這是否是你想要什麼:

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)); 
+1

這不是我要找的。例如,用戶只能在澳大利亞的能力退出此界限(LatLngBounds澳大利亞)的地圖中導航。 –

+1

我發現[this](http://stackoverflow.com/questions/14977078/limit-scrolling-and-zooming-google-maps-android-api-v2),也許可以給你一個想法。我認爲你是正確的,但也許你的方法是問題。 – Aiapaec

0

你可以做到這一點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);