Reputation: 135
I'm trying to use a google map with options such as disabling zoom gestures. I have added GoogleMapOptions in the code below, in the same way I've seen done in random pieces of source code online. The problem is it just doesn't work, I can set all the zoom controls to false but it doesn't seem to change my application when I run it.
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMapOptions options = new GoogleMapOptions();
options.zoomGesturesEnabled(false);
MapFragment.newInstance(options);
map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
Can anybody tell me what's wrong with my code?
Upvotes: 1
Views: 2247
Reputation: 489
Instead of using
GoogleMapOptions options = new GoogleMapOptions();
options.zoomGesturesEnabled(false);
MapFragment.newInstance(options);
map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
you can get the UISettings of the GoogleMap object and play with them according to your needs. For example, if you want to disable the zoom gestures, you can simply add after the getMap() function:
map.getUiSettings().setZoomGesturesEnabled(false);
In the same way you can also disable the default zoom controls ("+" and "-" buttons to zoom in and zoom out):
map.getUiSettings().setZoomControlsEnabled(false);
and manage the other typical GoogleMaps interactions (Compass control, Tilt, Scroll and Rotate interactions).
Moreover you can disable all in once with
map.getUiSettings().setAllGesturesEnabled(false);
Note that, if you have the map as Fragment in a ViewPager, with: mMap.getUiSettings().setScrollGesturesEnabled(false); you can let control the left and right scroll to the PagerAdapter instead of having them the effect of a scroll of the map.
Regards, Andrea
Upvotes: 2
Reputation: 986
Yeah. Follow the directions here: https://developers.google.com/maps/documentation/android/map
My code looks like this:
jGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// jGoogleMap.getMyLocation();
jGoogleMap.setMyLocationEnabled(true);
currentLatLng = new LatLng(jCurrentLocation.getLatitude(),
jCurrentLocation.getLongitude());
jGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng,
15));
jGoogleMap.addMarker(new MarkerOptions().title("Current Location")
.position(currentLatLng));
jGoogleMap.setOptions( { draggable: false, zoomControl: false,
scrollwheel: false, disableDoubleClickZoom: true});
Upvotes: 0