How to solve Google Map zoom level issue in android - 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.

Related

Android - Two Maps in one App

I got an App where on main screen show google mapView. But I need also in details view show the map.
I know that it is impossible to run two maps simultaneously. Everything is working when I want to show something on the main map and later in detailed view, but when I come back to main one, it stops.
How to stop main map and come back later to it?
Having two maps in one app produces many weird application behavior. For example, Ive had overlays from one map show up in the second map.
That said, it is possible to have two maps in one application without the above happening. What you need to do is to specify a new process for the second mapview:
<activity
android:label="#string/app_name"
android:name=".SecondMapActivityName"
android:process=":SecondMapProcess"
>
</activity>
The above code lies in the manifest and is for the activity containing the second MapView. This way a new process starts for this activity within the same app and both your maps behave as they should.
What I do is create a new mapview in code each time I want to use it (yes overhead but it works ;)).
mMapView = new MapView(this, MAPS_KEY);
setContentView(mMapView);
mMapView.invalidate();
If you don't need to interact with your other map, you can use it in lite mode:
https://developers.google.com/maps/documentation/android-api/lite
It creates a bitmap image that looks like a map.

Refresh map in Activity does not react

I have an activity that extends MapActivity and has two main elements, list view on the left and map on the right. I put a refresh button on the map and tried to :
map.setTraffic(true);
map.invalidate();
but nothing changed. the map did not refresh. I did searched a bit on google and understood that invalidate() should do the trick. I would like to avoid recreating the entire activity. Please help? Thank you.
You should not even need the invalidate(). This sample app toggles between regular and satellite tiles just by calling setSatellite() when you press the <S> key in the emulator.
Temporarily switch to setSatellite() instead of setTraffic(). If that works, then the problem is tied to the traffic tile set, which I have never tried.

Maps Activity single mapview

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.

Android: Bottom of Google Maps gets black inside the application

I have one Map on my main activity and It works fine. Recently I added another small map view on one of my sub activities using the same google map key. Now when I press back after looking at the map on sub activity, it returns to the main view and bottom of the map on main activity turns black. See the attached image.
Is there anyone who has faced this problem and know why sometimes bottom of map turns balck?
You can only have 1 map activity per process.
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapActivity.html

Problems when my googlemaps view activity regain the focus (map with black zone in down part of the window)

i have a problem with my app, it haves a lot of activitys, two of them haves googlemap views. My A activity haves a full mapview and my B activity haves a small map view. OK, when i am on the B activity and press back key somethimes until i return to my A activity, the map of my A activity shows with errors, with a black zone in the down part of the window. THis only happens when i press back from the B activity.
Because this, i need to implement/override onResume() method of A to RESTART THE ACTIVITY TO REPAINT ALL FROM SRATCH.... LIKE TO DO AGAIN ONCREATE METHOD, but i think i can't call it again... or i can?
wich code i have to put to repaint all the window from scratch ?
i tryed with all this:
-mapView.requestLayout() --> it works a little, repaints the map but with the zoom and showing the last map showed on B activity... no sense :S i dont want that. Are different maps, not have to show the same coordinates and zoom, each one have his own.
-mapView.invalidate() --> doesn't works
-mapView.postInvaldiate() --> doesn't works
Having multiple maps (MapViews) running in the same process is not adviced. Typically, using the default configuration, all Activities (including MapActivities) run within the same process.
According to the api docs, located here
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapActivity.html
Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways.
Issues I encountered with multiple MapViews within the same process :
Although it appears that there are 2
different maps in the app, changes in
the first map (ex: moving it to a
certain position, toggling sattelite
view) also got reflected in the
second map, as if it was the same
map.
On occasion, map tiles were not
getting loaded properly. Portions of
the map, or the complete map remained
empty.
In Logcat, apache http connection pool errors were logged (originating from the TilesProvider)
There is a defect logged here : http://code.google.com/p/android/issues/detail?id=3756
A solution / workaround is to host your maps in different processes :
<activity android:name=".MapView1" android:process=":MapView1">
<activity android:name=".MapView2" android:process=":MapView2">

Categories

Resources