I have a maps application using the new v2 Google Maps API for Android. What I am trying to do is allow the user to draw a line on the map that follows the path of their finger. I understand I will probably need a button to enable/disable this functionality as it would obviously need to disable the pan/zoom controls. Once a user draws their line I need to be able to join the ends up to form a polygon. Does anybody know how this can be done? Really appreciate any help!
I think you could achieve this by using a framelayout that overlays a view above the map fragment. Listen for touch events on that view and set it's visibility to GONE once the user wants to disable the drawing so it wont fire your touch listeners and instead fire the maps ones.
An alternative would be to use a marker instead of allowing freeform drawing, you can easily listen for marker drag events and draw lines when the drag events finish.
Closing the polygon would be as easy as drawing a line from the start to the last line's end.
This will allow you to raw on the map https://developers.google.com/maps/documentation/android/lines
Related
Basically, my app will function a bit like Pokemon Go. I'm using mapsforge and offline maps. At the moment the app allows auto rotate(fine), tapping(fine) and map movement, like dragging or scrolling(not sure which event does that).
I just need the app to not allow dragging/scrolling of the map. Everything else should be allowed.
Any insight would help.
You can have a view on the top of your map.
That View can handle all touch events and do not give it to the map.
I've got a Mapbox map working with custom markers. I've got an issue in that when I'm interacting with the map, regardless of type (zoom, pan, tilt etc) and number of fingers used, if one finger starts on a marker then that event will not work. The marker click listener doesn't get called, so it seems that the marker isn't consuming the event. I'd added logging to the other event listeners on the Mapbox view and none of them are being called either (OnCameraChangeListener, OnMapClickListener, OnScrollListener, OnFlingListener etc)
Debug mode on the Mapbox view is enabled.
The problem is that we have a lot of markers in a very small area, and it's almost impossible to manipulate the map.
We are working on a fix for this, you can track the progress here. One thing to note is that the fix most likely will break a few APIs in the SDK which means the fix won't make it till the 5.0 release of the Mapbox Android SDK. Hope this helps!
How do I disable a new pin being dropped when a user touches the map? This seems like this should be obvious, but I can't find it anywhere! Basically map comes up with my custom pins, user touches anywhere on the screen, a dummy pin appears and mine disappear.
You might want to change the draggable(boolean) function in markerOptions, you can set the draggable to be false.
For more information about a draggable market, you can visit this documentation.
I'm dumb. I got a little copy and paste happy and had that as part of a listener.
On a custom event, I need my Marker to update its drawable 6 times (basically, I want the Marker to grow and shrink 3 times with a delay of 0.5 s between each growth and each shrink) so it notifies the user of said event.
Is there any way to achieve this without actually having to remove the Marker and adding it again with a different Drawable?
Marker has a new function added as of rev.7 of API v2. Marker.setIcon. Have fun animating.
I'm afraid there is no way to do it today without actually removing the marker and adding it again with another drawable. I have just done so myself in an attempt to create a progress bar. It works, but it is an awkward way of doing it.
Click here for a good explanation in another thread.
I want to give my users oppertinty to choose destination. from the beginning it will already have a point on the map, and after that they can choose/change to another location if they want..
how is it possible to change the point on the map, by clicking somewhere else on the map?
I assume you're talking about a MapView within your application, and not in the Google Maps app. There's a method on a MapView called onTouchEvent(). This callback will be called when a user clicks (or touches) on the map, and you can read the location of the touch from the MotionEvent object that's passed in. From there you can decide what you want to do.
Another way is to extend the Overlay class, and add it to your MapView's Overlay list. Overlay has a method called onTap(), which gives you the GeoPoint where the touch took place. You can then animate to that spot using the MapController to center the map on that spot.
If all you want to do is pan the map sideways, a user can simply touch and drag the map.
For these things to work the MapView must be clickable (settable in XML or with code).
The relevant reference pages are here:
URL to Android Maps API
i think this tutorial is perfect one. You should read carefully content of source code. That's all what u need to do.