【问题标题】:Android Studio Google Maps custom Map, Only want to display the custom map but make use of google maps featuresAndroid Studio 谷歌地图自定义地图,只想显示自定义地图但利用谷歌地图功能
【发布时间】:2020-04-17 15:32:37
【问题描述】:

我知道标题可能会造成一些混乱,我会尽力在这里解释一下。我正在尝试为慈善机构创建一个应用程序,他们想要一个可以导航的网站地图。我目前正在使用谷歌地图叠加功能。我几乎得到了想要的结果,但有些事情我无法理解。

    @Override
    public void onMapReady(GoogleMap googleMap) {
    //LatLng NEWARK = new LatLng(51.251115, -0.599319);

    LatLngBounds NewarkBounds = new LatLngBounds(
            new LatLng(50.807686, -0.430219),
            new LatLng(50.811414, -0.424310)

    );

    mMap = googleMap;
    mMap.getUiSettings().setMapToolbarEnabled(false);
    //mMap.addMarker(new MarkerOptions().position(NEWARK).title("Reserve"));


    LatLng myPosition = new LatLng(latitude,longitude);


    GroundOverlayOptions newarkMap = new GroundOverlayOptions()
            .image(BitmapDescriptorFactory.fromResource(R.drawable.maptest))
            .positionFromBounds(NewarkBounds)
            .visible(false);


    if((myPosition.latitude <= PLACETEXT && myPosition.latitude >=PLACETEXT ) && 
    (myPosition.longitude >= -PLACETEXT && myPosition.longitude <= -PLACETEXT )){
        newarkMap.visible(true);
        mMap.setMyLocationEnabled(true);

    }
    else {
        mMap.setMyLocationEnabled(false);
    }

    GroundOverlay imageOverlay = mMap.addGroundOverlay(newarkMap);


    mMap.setMyLocationEnabled(true);
    mMap.setOnMyLocationButtonClickListener(this);
    mMap.setOnMyLocationClickListener(this);


    mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(myPosition.latitude, 
    myPosition.longitude)));
    mMap.setMapType(0);
    mMap.setLatLngBoundsForCameraTarget(NewarkBounds);
}

这是我的 OnMapReady 功能,我尝试过使用缩放功能等,我对这些东西很陌生,所以我可能会做一些根本错误的事情。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

</androidx.constraintlayout.widget.ConstraintLayout>

布局文件^^

上面的图片显示了当前显示的内容,忽略它是占位符的地图,我想要实现的是完全放大人的当前位置,并且只能在照片周围拖动到边界地图的LatLngs?

【问题讨论】:

  • 我觉得这是不可能的?我想知道您是否可以以某种方式使用谷歌创建自定义地图并将其导入而不是谷歌地图预定义地图?

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


【解决方案1】:

这是可能的。请查看 Google 在 Setting boundaries 上的文档。

代码 sn-p 将相机设置为范围内可能的最大缩放级别:

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

在边界内将相机居中:

private GoogleMap mMap;
private LatLngBounds AUSTRALIA = new LatLngBounds(
  new LatLng(-44, 113), new LatLng(-10, 154));

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(AUSTRALIA.getCenter(), 10));

限制用户在范围内滚动和平移:

private GoogleMap mMap;
// Create a LatLngBounds that includes the city of Adelaide in Australia.
private 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);

希望这会有所帮助!

【讨论】:

  • 嗨,埃文,抱歉回复晚了。这是最有帮助的!
  • 很高兴听到! :)
  • 嗨埃文,这已经解决了我的大部分问题,但仍然存在一个非常令人沮丧的问题,由于某种原因,地面覆盖层周围有一个灰色的填充物,我似乎无法修复。我可以破解它,但它会弄乱纬度/经度。这个项目似乎有同样的问题,但从来没有解决方案? “stackoverflow.com/questions/41606414/…”有什么想法!??
  • 如果不清楚,我已经发了一个新帖子。 stackoverflow.com/questions/60116647/…
  • 嘿!当然,我会调查并回复你:)
猜你喜欢
  • 2014-02-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-21
  • 1970-01-01
  • 2011-01-23
  • 1970-01-01
  • 1970-01-01
  • 2018-01-13
相关资源
最近更新 更多