i working with osmdroid and i want to change the TileSource at runtime (via menu entry). For example i can change between OSM TileSource and GoogleTileSource.
Problem: Everything works fine, but when i change the TileSource while the mapview is loading a Tile in the background, it changes the TileSource but one or two tiles are from the TileSource befor. So i see a mixed MapView with OSMTiles and one or two GoogleTiles.
The tileCache is cleared everytime after changing the TileSource. But the loading tile in the background isnt in the cache at this moment, so he put this tile to the cache, after clearing it.
Any Idea to workaround this issue?? It is all based on osmdroid, i only work with setTileSource(ITileSource)
Thanks and Greetz
Looks like a proper bug to me. I think you should report it as such. I can not see anything like it in the issues list. It looks like the bad tile even gets into the wrong cache on the sd card which is bad as it will be there for a while.
If you are using osmdroid3.0.6.jar (and I think you are, as I can reproduce this bug if I build with 3.0.6). I think it's another manifestation of the issue I raised osmdroid-android-3.0.6.jar, tile loading slow or fails. This bug has been accepted by the authors.
I suggest you go back to using the 3.0.5 jar. I don't get any problems with that. (I'm still puzzled as to how you get to use Google tiles with Osmdroid)
I think we all think it is a bug (or maybe it is not wanted to switch the TileSource at runtime).
I created a little Workarround. It works but it is not realy nice or recommended.
I created a new mapView and extend the osm MapView. Than create a RequestCompleteHandler, so i can see when a tile is finish loading and saved into the cache. Than i count every cached tile and only allow to switch the tileSource after 15 tiles are loaded. (at the start of the app osmdroid will load 15 tiles and only load some more after moving the map)
class RequestCompleteHandler extends SimpleInvalidationHandler{
private LbsMapView mMapView;
public RequestCompleteHandler(LbsMapView pView) {
super(pView);
mMapView = pView;
}
#Override
public void dispatchMessage(Message msg) {
super.dispatchMessage(msg);
Log.d("DEBUG", "HANDLER HAT GERUFEN! BACKE BACKE KUCHEN!! " + tileCount);
tileCount++;
}
}
then override the setTileSource method:
#Override
public void setTileSource(ITileSource aTileSource) {
if(tileCount <= 15){
Toast.makeText(mContext, "Jetz eher nich", Toast.LENGTH_SHORT).show();
} else {
tileCount = 0;
super.setTileSource(aTileSource);
}
}
and you need to set and initialise the Handler in the constructor:
mHandler = new RequestCompleteHandler(this);
getTileProvider().setTileRequestCompleteHandler(mHandler);
done. Now you can switch the tileSource only when it allready loads 15 tiles.
A little Problem: if the source are not working and do not load any tile you are in problems :D
But important: it is not recommended, its realy ugly code
Related
I have a ListView extending ArrayAdapter. I am using a view holder patter for the getView and here is a part of my getView method which loads images using picasso. The following code is expected to load images into my image view inside every list item.
Picasso.with(mContext).load(imageURL).fit().into(holder.myImageView,
new Callback(){
#Override
public void onError() {
holder.myImageView.setVisibility(View.INVISIBLE);}
#Override
public void onSuccess() {}});
So here is the problem: this works fine for OS < Android 5.0, but in the case of Android 5.0 (Lollipop), it looks like Picasso is fetching these images when my app is installed and run for the very first time, but when I launch the app again, the images don't load. Not at all sure what the problem is. I am not loading huge images, you can assume all the images that I am loading are only of the size of a small icon/thumbnail (around 120X120). I am using Picasso 2.4.0 for my application and the phone that I am using for testing is the Nexus 4.
Open Issue as of this edit: https://github.com/square/picasso/issues/633
Alternative:
I struggled to find an answer for very long time yesterday night. I explored Picasso really intimately trying several stuff. None did work. So right now what I am doing is:
if(api>=21) //Keeping in mind about any updates beyond 21
Use Android-Universal-Image-Loader
else
Use Picasso
For more information on Andorid Universal Image Loader.
Please visit https://github.com/nostra13/Android-Universal-Image-Loader
Its awesome with its cusotmization.
Agian, dont get me wrong, I am 100% +ve there is a solution with Picasso, I am sure I will find it someday, I will post it here then, but for anyone who have problems like me, I think the above is the way to go. Please suggest if you have anuy other better way.
************************ ISSUE FIXED **************************
https://github.com/square/picasso/issues/632
https://github.com/square/picasso/pull/860
************************** ISSUE FIXED ****************************
I have 2 MyGameScreen objects that extends cocos2d::CCLayer. I am capturing the ccTouchesMove of the first screen so that I can create the moving effect exactly like sliding between pages of iOS application screen.
My class is like so:
class MyGameScreen: public cocos2d::CCLayer {
cocos2d::CCLayer* m_pNextScreen;
}
bool MyGameScreen::init() {
m_pNextScreen = MyOtherScreen::create();
}
void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event){
// it crashes here... on the setPosition... m_pNextScreen is valid pointer though I am not sure that MyOtherScreen::create() is all I need to do...
m_pNextScreen->setPosition( CCPointMake( (fMoveTo - (2*fScreenHalfWidth)), 0.0f ) );
}
EDIT: adding clear question
It crashed when I try to setPosition on m_pNextScreen...
I have no idea why it crashed as m_pNextScreen is a valid pointer and is properly initialized. Could anybody explain why?
EDIT: adding progress report
I remodelled the whole system and make a class CContainerLayer : public cocos2d::CCLayer that contains both MyGameScreen and MyOtherScreen side by side. However, this looked like not an efficient approach, as when it grows I may need to have more than 2 pages scrollable side by side, I'd prefer to load the next page only when it is needed rather than the entire CContainerLayer that contains all the upcoming pages whether the user will scroll there or not... Do you have any better idea or github open source sample that does this?
Thank you very much for your input!
Use paging enable scrollview.download files from following link and place in your cocos2d/extenision/gui/ after that you have to set property of scrollview to enablepaging true with paging view size.
https://github.com/shauket/paging-scrollview
For Scene Transitions you can do this:
void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event)
{
CCScene* MyOtherScene = CCTransitionFadeUp::create(0.2f, MyOtherScreen::scene());
CCDirector::sharedDirector()->replaceScene(MyOtherScene);
}
This is very, very strange. I've never seen anything like it. At the time I am took this screenshot, I'm not loading any overlays. First, I thought it was my internet connection where it couldn't download the tile information; but we have many users reporting the same issue who downloaded from the market. This just started happening like a week ago. Not sure why though. Anyone have a clue? Thanks!
Ok. After starting from a clean project I found these two lines of code that was the culprit.
mapView.setSatellite(true);
mapView.setStreetView(true);
They appeared back to back of each other and I looked back at the very beginning of development and they were there and it worked just fine. Apparently, this is a BUG in the MapView as I'm guessing it tries to show both SateliteView and StreetView at the same time. One would think that the latter would override the former; but I guess not.
So, the question I have is, why this all of the sudden surfaced just within the last week or so. My guess is that the Maps Application was last updated in the market on Sept 8th and maybe a day or so after updating from the market, this issue started to resurface.
As a test, can someone just add these two lines to their code and confirm you get the same behavior?
I had only setStreetView(true) and getting those annoying grey boxes. I played around with both lines with no luck. Solved it by removing both setStreeView and setSatellite from my code, goes to streetview by default.
I had the same problem with my app that uses google maps library... Because i have in my setting option where user can change view of the map to Satelite or Street, i dont use setStreetView(true) at all...just mapView.setSatelite(true or false)...
preferences = PreferenceManager.getDefaultSharedPreferences(this);
pogled = preferences.getString("list", "Street");
if(pogled.equalsIgnoreCase("Street")){
mapView.setSatellite(false);
//mapView.setStreetView(true);
}else if (pogled.equalsIgnoreCase("Satelite")) {
mapView.setSatellite(true);
}
As you can see i had mapView.setStreetView(true) but that gave me a headache... :D I hope this will help you...
I removed setStreetview(true) from my code and now its working fine i was saw this issue occured in last 2 weeks , nyway we finally solved the issue thats great
Street view is always considered as the default option.
The problem arises when we use both setStreetView(true) and setSatellite(true) at the same time. Problem will be solved like this
if(mapView.isSatellite()){
mapView.setSatellite(false);
}else{
mapView.setStreetView(false);
mapView.setSatellite(true);
}
I hope that will help
private void setUpMapTypeScreen() {
if (mapType.equalsIgnoreCase("Satellite")) {
mapView.setSatellite(true);
// mapView.setStreetView(false);
} else if (mapType.equalsIgnoreCase("StreetView")) {
mapView.setSatellite(false);
// mapView.setStreetView(true);
}
mapView.invalidate();
}
mapType is a user defined string variable. Not false the previous view type when switching to view types. that the error we made, only set the view type you required.
I had the same problem, I took out my mapController, and it fixed it. The only other thing I did different was put the mapview in a linearlayout with a textview (it used to just be a mapview only) and I played around with the mapcontroller, commenting it out.
Since those are the only two things I changed, I'm pretty sure your problem lies in there as well.
I was having the same problem and the common advice that I have got is to not use setStreeView(true) and setSatellite(true) together. Some have even suggested not to use setStreetView(true) altogether. But my code was working okay before. I had to reinstall my machine and therefore installed android SDK and other components afresh after which this started happening. So my guess is that this is an issue with some specific version But I have found out that this problem occurs specific revision of 2.2 - in my case Android SDK Platform 2.2, revision 3. I have tried running same code on 2.3 and it works correctly i.e no grey boxes.
Besides removing mapController.setStreetView(true), there is also another thing that should be added to the layout XML..
xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapa"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="YOUR API KEY"
android:clickable="true"></com.google.android.maps.MapView>
Note the xml namespace after com.google.android.maps.MapView. After adding the namespace, the cross tiles disappeared. Don't know if it's a bug or the namespace is necessary in order for the api render the map correctly. Either way, it worked.
I see this exception sporadically raising up in my application (in the wild).
The WebView is used to display a jpg (using the zoom/scroll-capabilities of the Android version/the device instead reinventing the wheel and do all the reflection stuff).
I have no idea why this exception eventually could come up. Basically I can only think of an Android bug.
What I do (everything in GUI thread):
display a thumbnail as preview first
set getSettings().setBuiltInZoomControls(false)
when the regular picture is loaded, display that one instead
set getSettings().setBuiltInZoomControls(true)
Why setting ZoomControls on/off: The thumb should not be zoomable, as the WebView resets this on loadData as soon as the regular picture is available and displayed. Would be some bad user experience.
Example device this is happening:
HTC Desire#htc_wwe/htc_bravo/bravo/bravo:2.2/FRF91/226611:user/release-keys
I have exactly the same device/software and it never happend to me...
Any ideas?
Regards,
Oliver
I don't like to answer myself, but littleFluffyKitty did not (only in comment).
Solution is in How to safely turn WebView zooming on and off as needed
a) create your own WebView class
public class MyWebView extends WebView {
b) add in it's onDestroy() method:
getSettings().setBuiltInZoomControls(true);
That's it. Thanks to that, no more of those Exceptions show up.
I currently have a Google Map Activity which is apparently working well but doesn't show the map (this sounds stupid!)
Here is a picture that will make you understand better my problem:
I already confirmed my apiKey, checked the tutorial over and over and even the manifest seems not be missing anything.
I get only this on adb:
276 MapActivity W Recycling dispatcher
com.google.googlenav.datarequest.DataRequestDispatcher#43ea39b0
276 MapActivity V Recycling map object.
51 GpsLocationProvider D setMinTime 1000
276 MapActivity I Handling network change notification:CONNECTED
276 MapActivity E Couldn't get connection factory client
Does anyone have a clue about what may be causing this?
Thanks.
Are you running the app signed with your key from your key store, or the debug key (clicking run in eclipse will sign the apk with a debug key and install it on the device - be it the emulator or a physical device).
If you have a map key (apikey), the keystore will have two different hash codes depending on whether you use the debug key, or your key - so you need two different map keys depending how you are running the app (the debug one will only be needed when you are developing the app).
Take a look at the debug section: http://code.google.com/android/add-ons/google-apis/mapkey.html#getdebugfingerprint
IF you are using setSatellite(boolean) and setStreetView(boolean) then you can face such situations. This is a BUG in Map View. Use only one of these two methods or you can try with some combinations of these two. Some times, use of only one of them solves the problem sometimes, you need to use a combination of both...like I did in my particular case..
streetView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mapView.invalidate();
mapView.setSatellite(false);
//mapView.setStreetView(true);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("satelliteView", false);
}
});
satelliteView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mapView.invalidate();
mapView.setStreetView(false);
mapView.setSatellite(true);
}
});
Are you sure that you are properly setting the API key for the MapActivity/View?. Can you post your layout xml and source code?
Make sure to follow the steps from this tutorial: http://code.google.com/android/add-ons/google-apis/maps-overview.html
It will also show a map like that if it you send it a fake lat/lon pair where there is no useful map data, eg. "geo fix 0.0 0.0" (North Pole)
Try "geo fix -0.1 51.5" (over South London) where there is Google map data.
The problem was that the coordinate was wrong and that way the map was so zoomed that it wasn't able to show anything.
I zoomed out and I there was the map; so it was a coordinate problem and not a key/map activity problem.
For those who can't zoom out in these cases add this to your code
mapView.setBuiltInZoomControls(true);
and in the layout
android:clickable="true"