android - 使用 Google Maps Android API v2 显示多个点

标签 android google-maps google-maps-android-api-2

我知道如何在 map 上添加点。

private void addMarkertoMap() {

        LatLng MarkerPos = new LatLng (24.803751, 1.479969);

        googlemap.addMarker(new MarkerOptions()

        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE))
        .position(MarkerPos)
        );

但是如果我有很多点(数百个)并且我想从 GML 或 KML 文件中显示它们怎么办?在谷歌地图 Android API 中是否可行?有什么帮助吗?

谢谢!

最佳答案

您可以只添加那些当前在屏幕上可见的标记(但请注意,您需要跟踪您在屏幕上添加的那些标记,这样您就不会一遍又一遍地添加它们。你甚至可能想要删除那些不再可见的)

mMap.setOnCameraChangeListener(new OnCameraChangeListener() {
   @Override
   public void onCameraChange(CameraPosition position) {
      final LatLngBounds screenBounds = mMapView.getProjection().getVisibleRegion().latLngBounds;
      for (YourPoint point : mPoints) {
         if (screenBounds.contains(point.getLatLng()) {
            mMapView.addMarker(point.getLatLng());
         }
      } 
   }
}

关于android - 使用 Google Maps Android API v2 显示多个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14822567/

相关文章:

Android Billing V3 订阅问题 - 订阅卡在无法取消的状态

android - 无法将 Android 手机连接到 Adhoc 模式

java - 使用 String.format 从右侧获取字符串

javascript - Google 地点 place.open_now

android - 如何在android中刷新 map 上的标记?

java - 安卓 : changing Locale within the app itself does not affect the first run

javascript - 如何获取两个位置之间路线的中心纬度和经度

PHP 为 Google map 生成的 JSON : a tiny mystery

android - 从 Google Map 的 setOnInfoWindowClickListener 接口(interface)方法替换 fragment 时 UI 挂起

android - 使用 Google Map V2 并打开虚拟键盘时 Android EditText 上的黑色矩形