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.
Related
I have been trying to find a way to get this done but keep running into issues.
I want to be able to have a map in a frame (it does not necessarily have to be a FrameLayout, i just want it framed so it only takes up 1/2 or 2/3 the screen) ontop of my current layout and to have the current activity still displayed behind it.
In a perfect world, i would like to attach this view to a button and animation so clicking the button causes this view to slide in from offscreen left and settle in the center of my current activity, while still being fully clickable and and the map being useable (can zoom, click, etc.)
I have tried doing this with a fragment, but the issue is that the Activity i am working in is already extending another class that is absolutely necessary, so i can not extend Fragment or FragmentActivity, so i cant use fragments (unless i am missing a work around to achieve this.)
The same goes for MapActivity and MapView, cant extend the MapActivity class so cant use MapView.
Any time i try to inflate a map view or anything i get runtime errors because my activity does not extend the pertinent class. Is there a work around for this?
Does anyone have a suggestion as to how i can get this map to display the way i am looking for?
This is easily achieved in iOS but i cant seem to figure it out in Android.
Thank you in advance
EDIT
I am not looking for code, unless you have a specific example in which case obviously code is very helpful, but i am looking for an idea as to how to achieve this -- a push in the right direction if you will -- so i can write the code myself.
Solved this by adding a frame layout to my "Main" activity. That frame layout's class was set to my Map class. The Map class extended FragmentActivity and its contentView is set to my map_fragment.xml. The map_fragment.xml contains only a fragment and that fragments name is set to com.google.android.....SupportMapFragment.
After setting up my project in this way as well as setting up the correct screen layouts and dimensions for sizing purposes as well as defining a GoogleMap in my Map class, i was able to display a fully usable and interactive map over my "Main" activity.
I overrode some Activity transition animations to the Map class and got my project working 100% how i want it to.
I didnt ask for code, so i will not supply any code, but this process is pretty straight-forward if you follow the same process as i have described above.
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.
I have a problem which has been driving me mad for days - I've trawled the Web but can't find the answer to what must be a simple problem.
I am writing an Android application which uses a map to display pins at specific locations. When the user taps one of the pins I'd like to display an info window with some additional details. Simple!
I have a class that extends MapActivity (and contains a MapView) and another that extends Overlay (note that I'm not using ItemizedOverlay due to the number of pins and performance was far too slow). In the Overlay class there is a hit testing routine which determines whether the user tapped on a pin or not and if so will display a simple rectangle above the pin with the details. It all works fine but does not look that great.
I want to display a nice speech-bubble callout which in time will also contain a button or two to perform additional operations. After a lot of looking around I found this blog post and it seemed to fit the bill. The post highlights the fact that the MapView that I have placed on my MapActivity is a ViewGroup so can contain additional views, i.e. one that represents my speech-bubble callout. However, while I can follow the partial source code I'm having problems wiring it up - that's where I need some help.
I've created my 9patch image and a layout to contain it and, as a test, if I put the code in the MapActivity class then I can get the callout to display. The issue is that I need to be able to determine which pin the user has tapped so that I can get the coordinates and the associated information and this is handled by the Overlay.
So, how do I wire this up so that when a user taps a pin on the Overlay the MapActivity is called to add the new 'Callout view' to the MapView in the appropriate location with the associated text?
Update:
Well I took a bit more time to look at the sample project cited in the blog post I refer to above and now have a working implimentation. I had previously dismissed this as it was using the ItemizedOverlay but the approach was sound enough. Basically I've revised my Overlay class to accept the MapView as a parameter in the constructor so now I have access to it without having to call back down to the MapActivity. It sounds simple enough but I was trying to leave the Overlay to do what it needs to do, i.e. display the markers, and not have to tinker with the parent MapView. Fact is that it works now and I can get on with the rest of the coding.
I am not sure of what exactly you are looking for. You can find a good tutorial to figure out which point as been hit during onTap and then retrieve the overlay and print out some stuff on the map.
To display the information on fix location you could put all your info components in place in your xml with visibility invisible and change it to visible if an overlay has been touched.
Hope this helps,
Stéphane
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">
I'm currently developing an app which uses tabs and google map. What I want to do is to get the gps positions, say 3, and store them in sql db (which I'm already doing) and then display them on the map. I already created canvas, added to overlay but those points disappear when I'm changing tabs so I thought if there is a way to somehow store those coords with google map so I can retrieve them and display them nicely whenever I'm clicking the "map tab"? Please can anyone help?
I don't have the answer for you but I know the issue is being caused by the change of view. This is the same as you get when you rotate the device and the screen resets. You need to do something with the onRestoreInstanceState(). The default of this restores the state of your UI. So you need to override it to save the data and readd it when the view changes.
Hope that helps. Someone else might have a code sample.
T
Use an ItemizedOverlay, and associate the overlay with the map in onCreate(). The overlay should not "disappear when I'm changing tabs".