我知道如何在SupportMapsFragement内部检测Maps onLongClick监听器。为了使这个功能有点直观,我在地图中有一个按钮,允许用户添加地理围栏。所以现在我的要求是,当用户点击按钮时,我希望屏幕是透明的,要求用户长时间点击地图上的任何地方。一旦用户长按Map,我想执行onMapLongClickListener。
有没有办法可以做到这一点?任何帮助表示赞赏。我无法弄清楚如何做到这一点。请在下面找到我到目前为止所尝试的内容。
MapsFragment.java
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
databaseReference.child("latitude").setValue(latLng.latitude);
databaseReference.child("longitude").setValue(latLng.longitude);
if (!geoSetAlready) {
setMap(latLng);
}
}
});
public void setMap(LatLng latLng) {
BitmapDrawable bitmapdraw = (BitmapDrawable) getResources().getDrawable(R.drawable.logoga);
Bitmap b = bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, 200, 200, false);
latlangForGeo = latLng;
MarkerOptions markerOptions = new MarkerOptions()
.position(latLng)
.title("name display")
.icon(BitmapDescriptorFactory.fromBitmap(smallMarker));
CircleOptions circleOptions1 = new CircleOptions()
.center(latLng)
.strokeColor(Color.argb(50, 70, 70, 70))
.fillColor(Color.argb(200, 00, 150, 00))
.radius(geofenceradius[0]);
CircleOptions circleOptions2 = new CircleOptions()
.center(latLng)
.strokeColor(Color.argb(50, 70, 70, 70))
.fillColor(Color.argb(50, 100, 00, 00))
.radius(geofenceradius[1]);
CircleOptions circleOptions3 = new CircleOptions()
.center(latLng)
.strokeColor(Color.argb(50, 70, 70, 70))
.fillColor(Color.argb(50, 255, 0, 0))
.radius(geofenceradius[2]);
mMap.addMarker(markerOptions);
mCircle = mMap.addCircle(circleOptions1);
mCircle = mMap.addCircle(circleOptions2);
mCircle = mMap.addCircle(circleOptions3);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 5));
// Zoom in, animating the camera.
mMap.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
mMap.animateCamera(CameraUpdateFactory.zoomTo(10), 1000, null);
geoSetAlready = true;
}
这是我的布局类。
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.project.group.projectga.fragments.GuardianMapsFragment">
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/fab_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|top"
fab:fab_expandDirection="down"
fab:fab_addButtonColorNormal="@color/loginbackground"
fab:fab_addButtonColorPressed="@color/Map"
fab:fab_addButtonPlusIconColor="@color/Map"
fab:fab_addButtonStrokeVisible="false"
fab:fab_labelStyle="@style/menu_labels_style"
fab:fab_labelsPosition="right">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/loginbackground"
fab:fab_colorPressed="@color/loginbackground"
fab:fab_icon="@drawable/ic_clear_all_yellow_24dp"
fab:fab_plusIconColor="@color/Map"
fab:fab_size="mini"
fab:fab_title="@string/remove_geofences" />
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/loginbackground"
fab:fab_colorPressed="@color/loginbackground"
fab:fab_icon="@drawable/ic_add_yellow_24dp"
fab:fab_plusIconColor="@color/Map"
fab:fab_size="mini"
fab:fab_title="@string/add_geofences" />
</com.getbase.floatingactionbutton.FloatingActionsMenu>