简体   繁体   English

Android Studio 谷歌地图自定义地图,只想显示自定义地图但利用谷歌地图功能

[英]Android Studio Google Maps custom Map, Only want to display the custom map but make use of google maps features

I understand that the title might add a little confusion, I'll do my best to explain it here.我知道标题可能会增加一些混乱,我会在这里尽力解释。 I'm trying to create an app for a charity, and they want a map for their site that they can navigate around.我正在尝试为慈善机构创建一个应用程序,他们想要一个可以浏览的网站地图。 I'm currently using the google maps overlay function.我目前正在使用谷歌地图叠加功能。 I've almost got the desired outcome, but there are a few things I can't get my head around.我几乎得到了想要的结果,但有些事情我无法理解。

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

This is my OnMapReady function, I've tried playing around with the zoom function etc, I'm new to this stuff so I might be doing something fundamentally wrong.这是我的 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>

Layout file ^^布局文件^^

上图显示了当前显示的内容,忽略它是占位符的地图

The image above shows whats currently displaying, ignore the map it is a placeholder, What I'm trying to achieve is to be fully zoomed in the person's current location, and to only be able to drag around the photo to the boundary of the LatLngs of the map?上图显示了当前显示的内容,忽略它是占位符的地图,我想要实现的是完全放大人的当前位置,并且只能将照片拖到 LatLngs 的边界地图?

This is possible.这个有可能。 Please have a look at Google's documentation on Setting boundaries .请查看 Google 关于设置边界的文档。

Code snippet to set the camera to the greatest possible zoom level within bounds:将相机设置为范围内最大可能缩放级别的代码片段:

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

Centering the camera within bounds:在边界内将相机居中:

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

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

Restricting the user's scrolling and panning within bounds:限制用户在边界内滚动和平移:

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

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM