I'm new to Android development and have some question regarding overlays in googlemaps API.
What I'm trying to achieve is a class that adds one and only one marker at the position where you tap, I want this overlay to be active only when a button "add marker" is pressed. I've solved this problem in two different ways and I'm not completely satisfied with either one of them.
My solutions is as follows:
first attempt:
A bool that turns true when "add button" is pressed, then you are able to put a marker on the map and the boolean value turns false.
This feels quite ugly and the overlay is always active and listens to every tap on the display, maybe this is't that dumb as I believe.
second attempt:
Temporary creates the overlay that creates the marker and then immediately removes it self.
This solution I just can't find efficient... Creating new overlay before creating a new marker.
Is there any way to just activate the overlay when "add button" is pressed? Maybe there is some other way to do this?
Is there any way to just activate the overlay when "add button" is pressed?
Don't add it to the overlays list until the add button is pressed.
Related
Consider a situation where we have several markers overlapping each other, specifically map is zoomed out. If we tap on marker it should return the top most but it is not returning the top marker.
Example: Consider there are four markers A, B, C and D overlapping, where D is at the top. If we tap on D it should return marker "D" but it is returning other than "D".
Is there any clue?
When you have overlapping markers like this it's best to think about grouping or clustering them and then allowing users to select from the markers grouped at that location. There are some open source solutions like this one or this one that you can use. I had a similar issue and ended up building my own marker grouping class to handle sorting between people, places, and other objects.
The only other work around I can think of would be to store references to all your markers in a collection so that, on click of one marker, you could search for others at the same location. If you were able to then distinguish between which marker is A and which marker is D you could manually trigger the click method for the marker you desire.
I have a similar problem. I think Google does it on purpose to allow users to select the markers even if they are overlapped. I found one thing: if the topmost marker wasn't tapped previously then this topmost marker will be selected. On the other hand if it was already tapped (even if it's not selected anymore) then the overlapped one will be selected. The workaround I used is to remember all your markers positions, remove them from map and add again. In this case MapView doesn't seem to remember which one was tapped and selects the topmost.
I also wonder if there's a way to just turn this behavior off?
I am doing a little project on Android with Google maps. And I have one question - it is possible to make marker draggable with single click on it, not after long press. For example: I click marker, it changes icon and I can drag it anywhere in map, and then after another tap he will not be draggable again and changes its icon back? (Marker must be draggable all the time from first tap to second even if you release it)
#user2595870:
Hello,
I know it should be in comment but due to less reputations i am suggesting you in answer.
You want to drag and drop facility for marker kind of thing ?
if so there is good example provided here. Please check it.
I'm using Polaris map library in my android app.
https://github.com/cyrilmottier/Polaris
I've Google Map with some geo points. I'm reading them from database. I've added two buttons on the map activity - "next" and "previous" to navigate between points.
mc.animateTo(geopoints.get(arrayID));
"arrayID" is the id of the next geo point and "mc" is map controller.
It works great but I want to add one more feature.
I want annotation to be visible by default while moving between points. After click on the "next" button I want to be moved to the next point on my map and it's annotation should be visible (not only after clicking on it).
Probably there is an easy way to do it.
I should probably do something with calloutView but I can't figure it out how to do that.
I made something like this. But it's not working properly.
MapCalloutView calloutView;
calloutView = new MapCalloutView(getApplicationContext());
calloutView.setDisclosureEnabled(true);
calloutView.setClickable(true); calloutView.setLeftAccessoryView(getLayoutInflater().inflate(R.layout.accessory, calloutView, false));
calloutView.show(mMapView, geopoints.get(arrayID), false);
calloutView.setData(annotations.get(arrayID));
It is showing me bubble but it creates new calloutView which is wrong I think. For example Polaris listeners are not working. I can't deselect callout etc...
My mistake! It was so easy...
I don't need to play with MapcalloutView in Polaris.
mMapView.setSelectedAnnotation(arrayID);
I have a map views which is have some markers on the map and a back button to the main page.
I also have a list of textview which is when selected, it will open a new page that have a button "View Map". The button "view map" will open up a map.
Each selected page has different map view which is different markers on it.
The problem is :
It works fine when I select the list of textview and "view map" button. The button back also functioning well. However, when i select another list and click the button view map, debug force close appear. I look for the solutions and the DDMS shows that "you are only allowed to have a single mapview in a mapactivity". How i'm going to fix this problem with the simpler ways without create another class or create new activity in android manifest.?
Refactor your map activity in a way so you can pass a bunch of data to it which will contain the information about the locations to be displayed. By doing this you can mark different sets of places on you map dynamically. For this you can either use on Overlay class in you map activity or for each set of markers an own Overlay class.
This should made it possible to use one MapView multiple times.
Another thing you should avoid is displaying a back button. Normally you don't need one as every Android device has a back button by design. So another back button might confuse your users.
My problem is that the zoom controls don't appear on the mapview after one click, i.e the first click after the application loads. (I am using the deprecated version.)
In my application, on a click I position a pushpin on the touched location and also generate a toast with the co-ordinates. After I click the map, the pin is re-loacated and the toast are generated (albeit a bit late, I guess because of the time for which they have to say on screen)
What is happening wrong? What gives? Are the two activities (pin and toast) stealing the touch event?
Can you suggest any alternatives?
I solved it myself, i had to add
mapView.displayZoomControls(true);
to the function that handled all the click events. but now it doesnt pan. ill see what i can do about it.
thanks.