|
HowToUseJar
How to use osmdroid in your application.
TODO update to use Maven - get jar from Maven repository IntroductionThis page explains how to use osmdroid in your own application. osmdroid's MapView is basically a replacement for Google's MapView class. In order to use it you should include osmdroid-android-x.xx.jar and its dependent files into your project. Contents
DependenciesYour project must be Android level 3 or higher (1.5 or higher). Include osmdroid-android-x.xx.jar and slf4j-android-1.5.8.jar in your project. If you are going to use OSMUploader then you must also include apache-mime4j-0.6.jar and httpmime-4.0.1.jar. Using itNow you can just use MapView in much the same way as the Google MapView. You can also use any overlays that you wish from the org.osmdroid.views.overlay package. There are many samples activities included with osmdroid. ManifestYou will need the following permissions in your manifest file: <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> If you want to use the Cloudmade tiles you'll need to include the following meta data: <meta-data android:name="CLOUDMADE_KEY" android:value="your API key" /> ResourcesAll resources used by osmdroid are included in the jar. However, if you wish you can use your own resources. You will especially want to do this in order to localise your application. To see an example of using resources from the application, have a look at MapActivity.java and its use of ResourceProxyImpl.java. |
Please explain how to build jar file from source code. I want to build jar myself from latest trunk version.
Got it. I could write a small wiki page, which explains how to build jar file from source. Will it be helpful to someone?
I was thinking about doing that as well, but it'd be good if you could do it.
it can be done by "ant build jar" ... you have to adjust the path to the android.jar package in build.xml (<path id="Android 1.6 jar.userclasspath">). That does work if you have Eclipse installed.
I have this setup:
I have a user library called "Android 1.6 jar" which points to C:\android-sdk-windows\platforms\android-4\android.jar.
osmdroid is in C:\workspace\osmdroid.
If you do the same then you don't need to adjust anything, otherwise you'll need to change the paths accordingly.
Perhaps someone could suggest how to modify the build files so that they use environment variables or some other property so that you don't need to change the build files.
You can also use File >> Export >> Ant Buildfiles to modify build.xml.
Hi! Me again... so when using the jar I don't have to write anything specific in the manifest xml file? I still can't display any map...
You'll need all the same permissions that OpenStreetMapViewer? has. But basically it's the same as Google Maps.
Guys, as far as I understand LGPG terms I need to provide a way for the end user to be able to modify the binary so that he can replace the version of osmdroid in my binary with any newer one. But also as far as I can see Android Builder packages everything in one big class file in apk. So if the user unzips apk he still won't be able to replace osmdroid and repack the binary. Could you please tell me how to resolve this issue?
Hi,
just tried to get an equivalent to Googles Hello MapView? going but there ist no MapActivity? in the osmdroid...jar. What do I have to do? Is there any tutorial for less experienced user?
Cheers
Can anyone point to a sample application using osmdroid?
Note: the latest SVN code requires an additional permission:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
a sample application? OpenGPX uses it (http://opengpx.sf.net or http://opengpx.svn.sourceforge.net/viewvc/opengpx/OpenGPX/trunk/src/com/opengpx/lib/map/)
I want to use jar as well. So I'm also looking for sample applications as well. Does anybody know other samples apps? OpenGPX doesn't show a map when installed (it gives: "no caches available")
I found another sample application: http://code.google.com/p/bikeroute/ Relevant code is in the following files:
http://code.google.com/p/bikeroute/source/browse/trunk/bikeroute/src/com/nanosheep/bikeroute/OpenStreetMapActivity.java
http://code.google.com/p/bikeroute/source/browse/trunk/bikeroute/src/com/nanosheep/bikeroute/RouteMap.java
http://code.google.com/p/bikeroute/source/browse/trunk/bikeroute/res/layout/main.xml
Credits to demonixz!
Thanks for the pointers to the sample apps. I've been able to convert my app from Google MapAPI to osmdroid API in a couple of days.
I am having one problem regarding OpenStreetMapViewProjection?.toMapPixels(GeoPoint?, screenCoords) The screen coords for a GeoPoint? that appears on the screen are large numbers and are not in screen coordinates (eg. 200,300). Can someone explain the coordinate systems?
Solved problem through trial&error. It appears that toMapPixels converts from lat,lon to world x,y coordinates, and fromMapPixels converts screen x,y coords to world x,y coords. This allows comparisons in the same coordinate system. Can anyone confirm?
Can anyone point to sample code that uses TileProvider? from CloudMade?? How does one specify using a different TileProvider? and the tile style? I have api key.
There's no example, but you can do a view like this
<org.andnav.osm.views.OpenStreetMapView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_centerInParent="true" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:id="@+id/osm_map" renderer="CloudMadeStandardTiles" cloudmadeStyle="1" />You should set your CloudMade API key in AndroidManifest.xml.
Thanks neilboyd!!! I had to change "CloudMadeStandardTiles??" to all caps but then all works.. One problem I noticed is that the cloudmadeStyle always defaults back to "1" even though I changed it to "2" See log file below:
I/org.andnav.osm.views.util.OpenStreetMapRendererFactory??(15547): Using renderer specified in layout attributes: org.andnav.osm.views.util.CloudmadeRenderer??@432cacd0
I/org.andnav.osm.views.util.OpenStreetMapRendererFactory??(15547): Using Cloudmade style specified in layout attributes: 2
I/org.andnav.osm.views.util.OpenStreetMapRendererFactory??(15547): Using default Cloudmade style : 1
I/org.andnav.osm.views.util.OpenStreetMapRendererFactory??(15547): Using renderer : org.andnav.osm.views.util.XYRenderer@432c9c18
I/org.andnav.osm.tileprovider.util.CloudmadeUtil??(15547): Cloudmade key: xxxxxxxxx
After more trials, it appears that the cloudMadeStyle = 2 is in effect despite the logs. I am getting both "1" and "2" style tiles in different areas of the map. Probably due to style "1" tiles are cached. Can i flush tile cache?
You need a build from the latest source to get the mixed case. I'll do a new jar a bit later.
You're right about it mixing the styles. It wasn't really designed to switch between styles. Perhaps you could make a bug report for it.
And I'll have a look at that thing where it reports 2 and then 1.
I fixed the logging in revision 395.
I want to use maptiles at an overlay from an custom server (base-url = http://overlay.openstreetmap.nl/openfietskaart-overlay/). (This overlay contains a national bicycle route network.) For this goal I'm trying to use the OpenStreetMapTilesOverlay? class (org.andnav.osm.views.overlay). However, after being busy a complete day, I'm still not successful. I keep on messing around with the renderer and the tileprovider.
Has anybody any examples or pointers on how to use the OpenStreetMapTilesOverlay? class with custom maptiles?
I created issue 98 to make Cloudmade style dynamically configurable.
I added OpenFietsKaart?. I added it as renderer, but judging by the look of it, it'd probably be better to add it as an overlay so that you can see the map underneath it.
Hi Neilboyd. Thanks for fast response.
The openfietskaart-overlay indeed is an overlay, so you indeed need a map underneath it. But then we get to my main challenge: how do you get the openfietskaart-overlay as an overlay over a normal map? What do I provide as tileprovider at the constructor of the OpenStreetMapTilesOverlay? class? Or should I use another class?
For your reference: Navigate with your webbrowser to http://www.openfietskaart.nl/ in order to see a result of the overlay over a map. It shows bicycle routes in and around the Netherlands (fiets kaart = cycle map).
Maybe I found the answer to my own question: Provide an instantiation of the class OpenStreetMapTileProviderDirect? to the OpenStreetMapTilesOverlay? constructor. An example of using the class OpenStreetMapTileProviderDirect? is shown at http://code.google.com/p/osmdroid/source/browse/trunk/OpenStreetMapViewer/tests/org/andnav/osm/views/util/OpenStreetMapTileProviderDirectTest.java
Good approach? (I don't have time to test this today, I will try later...)
Let me know how it goes. What I may need to do is keep it as a renderer in the factory, but not return it in the list.
Hi Neilboyd, While trying to get things working, I want to let you know: 1) The samples SampleWithMinimapItemizedoverlay? and SampleWithMinimapItemizedoverlayWithFocus? crash if you tap on the map. 2) Another great renderer is the OSM Public Transport (http://tile.xn--pnvkarte-m4a.de/tilegen/). Suggestion: also add to the list of renderer.
I'm not fully succeeded.
I created the Sample "SampleWithTilesOverlay?" within the OpenStreetMapViewer? project. This is the most relevant part of the code:
IRegisterReceiver registerReceiver = new IRegisterReceiver() { @Override public Intent registerReceiver(final BroadcastReceiver aReceiver, final IntentFilter aFilter) { return null; } @Override public void unregisterReceiver(final BroadcastReceiver aReceiver) { } }; mProvider = new OpenStreetMapTileProviderDirect(new Handler(), "key", registerReceiver); this.mTilesOverlay = new OpenStreetMapTilesOverlay (this.mOsmv, OpenStreetMapRendererFactory.FIETS, mProvider, this.getBaseContext()); this.mOsmv.getOverlays().add(this.mTilesOverlay);The following errors shows up many times when you start zooming or moving around (or direct at startup):
I can send you the Sample class. My goal was to let it be a sample for other developers as well.
Hi Alex
1) I added a note to revision 383. 2) I added öpnvkarte and removed OpenFietsKaart? from the list of renderers.
Please submit your overlay sample even if it's not working properly. You can create a new issue for it.
Neil
I created issue http://code.google.com/p/osmdroid/issues/detail?id=101
For those of you who want to have US road symbols in CloudMade? tiles, please see this forum question on CloudMade? and add your support. The link is
http://support.cloudmade.com/forums/web-maps-studio/posts/990/show?page=1#post_1008
Hello Neilboyd, thanks for the previous response and sorry to bother you again, but I've tried to include osmdroid-android-1.07.jar to my project, and it just didn't work. I've added permissions to the manifest file, and I've imported the jar file, and when I try to: import org.andnav.osm.views.OpenStreetMapView?; for example, it gives me an error message: The import org.andnav cannot be resolved! Should I add uses-library to the manifest file or something like that? And when I tried to include the source files from the trunk, from the Market 2.0 project, everything worked fine, except the contour lines of the tiles, and some numbers in the upper left corner. Sorry for bothering you again and thank you for your time.
Btw, any example for displaying route between two GeoPoints?, I need just a static route, for example: you have current location and a static point on the map, and I would like to draw the route between them...
Hi ,
I've just started using the library. I ran the SampleWithTilesOverlay? example and I've noticed that on my HTC Desire the map looks a little blurry at higher zoom levels, as in the images which make up the map are of lower quality. Do you have knowledge related to this type of issue?
Thanks
Probably the source you checked out doesn't match the source that was used to build the jar. If you look in the manifest in the jar it tells you which version was used.
oh neil, just saw your comment after deleting mine. Guess that was it. Just updated the .jar. Thanks
could someone please explain this comment on OpenStreetMapViewProjection?? " This class may return valid results until the underlying- {@link OpenStreetMapView?} gets modified in any way (i.e. new center)."
thank you! and is there a place with more documentation than this wiki?
Tiles are blurry... some scaling is being applied, might be a pixel density issye
Hi All,
Can anyone provide a sample code using latest osmdroid-android jar? As in latest jar, there is no such class called OpenStreetMapView?, rather MapView? is present.
Thanks, Kishore
The Cloudmade link is dead.
I changed the link
Does one need to use Cloudmade? Is there a default tile provider? If so, how do you specify it? I'm converting an app of mine from Google.
I don't have a Cloudmade APIkey, and I don't want one. Is it simply a matter of setting 'renderer='Osmarender'' in the layout file for my MapView?? Just doing a flat conversion from Google, the rest of my application works, but my underlying map view is black. :(
Just need the hint, whatever it is. Thanks, -Polar
Just curious, if I wanted to use osmdroid for a project but wanted to it to use another directory on the SD card other than '<sdcard>/osmdroid', do I need to change the source or is there another approach. It appears to be hardcoded to a final constant.
I am also interested if there is an easy way to change a directory where map tiles are saved. It would be really useful if this was possible without modifying the source code.
I created issue 234 to specify the tile location.
Hi guys.
In your sample apps, is there any reason why you create the layouts programmatically rather than using .xml files?
Great work by the way.
Hi, first of all....very impressive map replacement, thanks! However I want to ask about this annoying issue that I'm having atm. When I add MapView? to my .xml layout file, the designer displays an error. I'm still able to compile and use the lib no problem from code. Have someone solved this yet? I would prefer to use the designer if there's a way...
org.osmdroid.views.MapView? failed to instantiate.
trace:
java.lang.UnsupportedOperationException?: Unsupported Service: connectivity
.....
at sun.reflect.DelegatingMethodAccessorImpl?.invoke(Unknown Source)
Hi, I have been working on a fairly large offline map based project for the travel industry. I have a problem that I get out of memory errors using osmdroid if I switch between two map activities nore than about 4 times (htc Wildfire). I looked at the memory usage on ddms and it seems to swallow about 2MB on every activity change. I force the cg in the onpause methods but this doesnt seem to help. Is there something known about this which I can easily fix. I have the tiles in the /osmdroid directory so downloading them is not a problem. The problem must be the caching of these when starting an activity.
hi to all! How do I use osmdroid-android-x.xx.jar library? I mean does it support displaying a map basing from OpenStreetMap?? .osm files are really big, what should I do to display a map without accessing the internet, I mean the map from OpenStreetMap? should accessed offline. Thank you, please reply if you read my answer. Thank you.
i do everythig as was write and create debug version with map. but when i try to do release (signed or not signed) i get proguard error
please help me resolve this problem...
It seems that using cloudmadeStyle in xml doesn't work any more? Is there a workaround or fix for this? Thanks..
The previous example is out-of-date. It should now be like this:
<org.andnav.osm.views.OpenStreetMapView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_centerInParent="true" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:id="@+id/osm_map" tilesource="CloudMadeStandardTiles" style="1" />Is it possible to turn caching to sd card off dynamically. The only way to disable it now as I can see is by removing WRITE_EXTERNAL_STORAGE from manifest.
Thanks in advance.
hello everyone, 1st of all, great project. I'm working fow few day on implementing it in my app, but I keep getting a LOT of problems, investigating most of them ends up with conclusion, that current versions 3.0.7, 3.0.8 dont implement the same methods as google-api and previous versions, that all examples and code snippets seems to follow. One example: ItemizedOverlay? doesn't have the onTap method, it does not support OnItemGestureListener? ...
in the end, I don't really know how to use itemiezedoverlay and how to add any new features to my app.
Any help/comment on that? Please ;)