Maps Activity single mapview - android

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.

Related

Button on a map image

I would like to have an activity where I have a simple world map as ImageView, where I could have multiple button in the map such that if I click on them I could be directed to a new activity. e.g. if I click on the location of France I link to a new activity for France etc.
I am rather new to android so I just drop the Button on top of the image, but then when everything is under relative layout I cannot control the position of the button well; in particular when the button becomes small then I can no longer move it around as I wish.
What is a more proper way of doing the same thing? Any kind advice appreciated.
Best,
Eddy

Adding buttons to map infowindow android

In the new Google Maps for Android API v2, I can very easily get custom markers and info windows to display. However, I'm trying to have multiple buttons inside of my info window, that each perform a different onClick action but the problem is, the map treats the InfoWindow as it's own button object (no matter where I click on the InfoWindow, it presses the entire thing). Does anyone know how to customize this a bit more?
Just found this in the documentation.
As mentioned in the previous section on info windows, an info window
is not a live View, rather the view is rendered as an image onto the
map. As a result, any listeners you set on the view are disregarded
and you cannot distinguish between click events on various parts of
the view. You are advised not to place interactive components — such
as buttons, checkboxes, or text inputs — within your custom info
window.
Unfortunately, that answers it. I was trying to add the same function as you.

MapPolaris and showing point bubble using button maps

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);

How to solve Google Map zoom level issue in android

Hi guys I'm developing an Android application which contains two google maps that are displayed one after the other. I have written two Activities for that namely:
CustomItemizedOverlay.java
CurrentLocations.java
The both of the above two Activities extends MapActivity.
Here first iam displaying CustomItemizedOverlay.java which consists of multiple markers and in this Activity i have an Image when click on that image iam displaying CurrentLocation.java which shows current location with a Marker. When I click the Hardware back button in the CurrentLocation.java I'm finishing this Activity and going to CustomItemizedOverlay.
In this Activity previously I have displayed several Markers but now I'm not able to see the Markers, whenever I'm decreasing the Zoom level then I'm able to see the markers. From this CustomItemizedOverly Activity if I go again to CurrentLocation Activity this time I'm not able to see the CurrentLocation Marker too except the case when I decrease the zoom level.
I don't understand why because I'm restarting the Activity. Any ideas?
I've had a few issues with the map view not refreshing in the past. From the sounds of it your map view isn't redrawing properly when the activity comes back into the foreground? If so try calling mapview.invalidate() in the onResume() override of the activity to force a redraw.

Android: google maps deactivate overlays

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.

Categories

Resources