【问题标题】:Limit the rectangular area, Google Maps V2限制矩形区域,Google Maps V2
【发布时间】:2014-01-15 14:57:40
【问题描述】:

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

【问题讨论】:

  • 您的意思是用户只能在某些地理区域内导航吗?
  • @El_Mochiq,是的,只能在矩形范围内导航。

标签: android google-maps


【解决方案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);

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 这不是我要找的。例如,用户只能在澳大利亚的 Capability 地图中导航退出此边界 (LatLngBounds AUSTRALIA)。
    • 我找到了this,也许能给你一个想法。我认为您的方法是正确的,但也许您的方法是问题所在。
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      • 2013-09-07
      • 2011-04-18
      • 1970-01-01
      • 2013-02-05
      • 1970-01-01
      相关资源
      最近更新 更多