Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Upgrade osmdroid #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

francoisfds
Copy link

Hello.

It seems that Mapnik tiles is suffering download errors on recent Android versions (due to limitations raised by the OpenStreetMap administrators).
For example an Android 10 device face this issue (whereas Android 5 don't have it).

This PR do the following :

Changes have been tested on Android 10 : working ; Android 5 is still working.

} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Configuration.getInstance().setUserAgentValue(context.getPackageName() + "/" + versionCode);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in MapActivity.java

e.printStackTrace();
}
Configuration.getInstance().setUserAgentValue(context.getPackageName() + "/" + versionCode);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we really need the versionCode in the UserAgent + I'd use BuildConfig.APPLICATION_ID which identifies the app, instead of context.getPackageName() (the package name can be different from the application ID).

So I'd replace the whole block with:

Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID)

(as suggested in https://github.com/osmdroid/osmdroid/wiki/Important-notes-on-using-osmdroid-in-your-app#set-the-http-user-agent-variable)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yeah it's true that the osmdroid does not officially recommend to go as far as this. Actually, as stated in my commit message I relied on the osmdroid github thread that pointed the issue, and more precisely a comment of an OSM sysadmin called Firefishy.
My understanding of the whole bug is that, at some point of the time when there was a single user-agent for every osmdroid client, it has been banned by the OSM Foundation because of overloading problems in which it was involved. Now the new osmdroid requires the customization of the user-agent so OSM could ban only the ending client that overloads its servers. In this context using the APPLICATION_ID would be enough. That said, the recommendation of Firefishy was to use a different user-agent for each app version to prevent the whole package to be banned forever if a specific version behaves badly for some reason.

@@ -93,7 +106,7 @@ protected void onCreate(Bundle savedInstanceState) {
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
map.setTileSource(new ThunderforestTileSource(context, ThunderforestTileSource.CYCLE));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this source require an API key?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I just made this change because the old code was not compiling, but it would be better to use a legit source instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have remove it. I can re-push with the removing unless you think about another source to add...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally re-pushed with another source (HikeBikeMap). Looking for your review. Regards.

This commit aims to get Mapnik working for newer Android versions,
which is done by upgrading osmdroid to latest. This update implies
some porting work :

- use Double instead of int argument when calling setMinZoomLevel.

- enhance osmdroid configuration : call 'load' to ensure config
(github.com/osmdroid/osmdroid/wiki/How-to-use-the-osmdroid-library)
and customize user-agent to access tiles following recommendations
(github.com/osmdroid/osmdroid/wiki/Important-notes-on-using-osmdroid-
in-your-app#set-the-http-user-agent-variable).

- replace the discarded OpenCycleMap tile source by HikeBikeMap.
@francoisfds francoisfds changed the title Upgrade osmdroid to v6.1.6 Upgrade osmdroid Nov 29, 2020
@francoisfds
Copy link
Author

Hello ! Please find a new PR including your suggestions and the new osmdroid updated in the meantime. Regards.

@ildar
Copy link

ildar commented Apr 27, 2021

then close this PR ( in favor of which? )

@francoisfds
Copy link
Author

Hi everyone. Sorry I missworded, actually I overwrited with a new commit, not a new PR 😛
See the commit tab, the current one (e1af67f) is up to date with the last demands of @bparmentier, and ready for merge if that's OK ?

Please let me know of any feedback about this.
Regards.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants