限制矩形区域,Google Maps V2

问题描述 投票:1回答:3

在我的应用程序中使用了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来做这件事,但它看起来很丑陋且不稳定。 (也许这是我的错)))

android google-maps
3个回答
1
投票

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

0
投票

我在google maps 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));

0
投票

看看https://stackoverflow.com/a/48473495/6117565。对于任何矩形区域,您必须知道纬线和长角。就这样。

© www.soinside.com 2019 - 2024. All rights reserved.