Android Studio Google Maps自定义地图,只想显示自定义地图,但要使用Google地图功能

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

我知道标题可能会增加一些混乱,我将尽力在此处进行解释。我正在尝试为慈善机构创建一个应用,他们想要为其站点导航的地图。我目前正在使用Google Maps overlay功能。我几乎可以达到预期的结果,但是有些事情我无法理解。

    @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函数,我尝试过使用zoom函数等,我是新手,所以我可能做的是根本错误的事情。

<?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>

布局文件^^

The image above shows whats currently displaying, ignore the map it is a placeholder

上面的图像显示了当前显示的内容,请忽略它是一个占位符的地图,我要实现的目标是完全放大该人的当前位置,并且只能将照片拖到该对象的边界地图的LatLngs?

java android google-maps google-maps-android-api-2 google-maps-api-2
1个回答
0
投票

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

将摄像机设置为在范围内最大可能的缩放级别的代码段:

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

希望这会有所帮助!

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