For an app I'm working on the user needs to be able to zoom in and out using pinch gestures, but only within a certain boundary.
There are multiple "levels" on which users can see the map and there should be a settable zoom boundary for each of these.
We got this working partially by resetting the camera back to the limit if pinching has brought it outside of it's boundaries, but the user shouldn't be able to pinch out/in of the boundaries at all.
Here's a video of how it's working now:
https://www.youtube.com/watch?v=WfAle_M-i0k
And how it should work is that once the camera is at the zoomlevel-limit, zooming out further shouldn't be possible.
This is important because we'll be drawing a lot of objects on the screen and the app crashes when it's zoomed out too far.
We're using the default pinch-zoom that comes with
mMap.getUiSettings().setZoomGesturesEnabled(true);
Is there a way to disable further zooming in/out when the boundary has been reached?
I don't see any other way of doing this that implementing zoom controls by yourself, i.e. setting
mMap.getUiSettings().setZoomGesturesEnabled(false);
and adding buttons on top of your map with actions with zoomBy inside (with respect to your zoom boundaries kept somewhere).
You may also check lite mode.
Related
I'm looking to achieve the same zoom as Uber and Lyft does.
When pinch to zoom I'd like to keep the map centered. I was able to do the double tap centered, but not the pinch, after some research those topics not helped :
First
Second
Any sample code or advices for this kind of feature ?
You will have to handle the Google Maps zoom_changedevent and set the center to the original center whenever this event is fired
map.addListener('zoom_changed', function() {
map.setCenter(center);
});
Further, this will stop the user from panning the map and then zooming again. If the user pans the map and then zooms it, the map will be reset to center which you might not want. However if the user does not zoom, he/she can normally pan through the map. You may want to clear this event listener for certain cases.
See a codePen here
PS: Use http only and not https while checking this codepen. I spent almost half an hour trying to get this work in JSfiddle but couldn't.
I need to build a screen with map of a theater, and user can interact with zoom in/out and choose seats on map.
When user touch on a seat, the icon of seat is changed.
Is there some lib/component to build my own map with touch areas? Or some good idea to use Android API to solve this problem?
Thanks.
You should take a look at the SurfaceView API.
It provides you with an easy to use abstraction for drawing on a canvas. You can use it to render your theater image and intercept touch events on it. However, zoom in and zoom out are not supported out of the box, so you should implement them separately.
Another thing you can do is show your image in an ImageView and use scaling to implement the zoom in/zoom out, but then intercepting the exact touch position can get a little tricky.
I've created an activity which shows a map v2. I would like to create a fixed pin at the center of the map. If panning around the screen the pin stays fixed at the view's center.
I've only found a tutorial showing how to create markers, but they keep they keep scrolling with the map when panning around. As an example, the UBER app uses this kind of fixed pin:
As you might see, the pin is in the middle of the screen and stays there also when panning around.
Any suggestions how to achieve that?
I am currently trying to figure out which way is best to display a picture in an Android app. The picture will be a map and will be a big picture (3000x3000 pixels). I would like to add the ability to pinch zoom into the picture and move the image around the screen but not have the scale of the image changed. I have played around with a lot of solutions that when the image is moved it is auto re-sized. Is there a way of doing this? Thanks.
However I have used many libraries for loading large images but subsampling-scale-image-view is the best library I found and also it supports a variety of gesture support.
Gesture detection
One finger pan
Two finger pinch to zoom
Pan while zooming
Seamless switch between pan and zoom
Fling momentum after panning
Double tap to zoom in and out
Options to disable pan and/or zoom gestures
Supports interception of events using GestureDetector and OnTouchListener
Extend to add your own gestures
Njoy!
I noticed that the position of the builtInZoomControls in WebView (bottom, horizontal right) is not consistent with the default position in the MapView (bottom, horizontal center).
1) Why is that not consistent? (Probably a question to be asked to Google)
2) Is there a way to horizontal center the builtInZoomControls of the WebView without applying custom Zoom controls? Or is that the only way?
From my experience with the Android UI, here's what i've noticed
When using a Maps activity, there is really no reason to align to the right, you are looking at a map, ie. a 2D surface that can be scrolled at will.
When browsing a website, most content starts at the left and runs right.
So, placing the control in the lower right while browsing the web makes a lot of sense, to keep it out of the way, when using maps (where the zoom control is more important), the control should be more prominent, thus in the center, where it still does not get in the way here.
Upon first reading your post, I was going to suggest using a custom zoom control, but I realize that you have thought about this already. If having centered controls is essential to your application, a custom control seems to be the route I'd take.
When viewing maps in a WebView you are actually using the Browser app to view the Map Tiles. In order to change the zoom controls when in Web View you would have to manipulate the zoom controls of the browser being used to view the Map Tiles.
You should try manipulating the WebView zoom controls and not the MapView zoom controls.