OpenStreetMap MapView for Android

Tutorials that use the MapActivity. Many using GPS functionality.

OpenStreetMap MapView for Android

Postby plusminus » Mon Sep 29, 2008 5:51 am

[align=center]OpenStreetMap MapView for Android[/align]

[align=center]Get the source: http://osmdroid.googlecode.com/ [/align]

Small example of my OpenStreetMap MapView for Android (it will be OpenSource in the end). Its will be a Open replacement for Androids own MapView-Class.

[align=center][youtube]http://www.youtube.com/watch?v=sq8fq4d-seA[/youtube][/align]

Stay tuned for updates and the first public release :D

Best Regards,
plusminus
Last edited by plusminus on Thu Nov 13, 2008 3:34 pm, edited 1 time in total.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby ninor » Mon Sep 29, 2008 6:26 am

VERY IMPRESSIVE!
Well done Nicolas!

Will it be possible to add overlays on top of it?
I suppose there's no handicap in adding overlays if it's a view like MapView.

You'll have to post this on the OpenStreetMap website. They'll be very happy!

:)


·
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby fabrantes » Mon Sep 29, 2008 10:25 am

Cheers nicholas! Looks a charm!

Given the restrictions we have on google maps for navigation I think this is a winner...

Keep it up (and if you need any help I'd be glad to join implementing).
fabrantes
Developer
Developer
 
Posts: 25
Joined: Fri Sep 05, 2008 3:13 pm

Postby ninor » Mon Sep 29, 2008 12:02 pm

It would be great if in the same OpenMapView component there's the possibility to activate sending automatically new track/street data to OpenStreetMap.org.

That way the contributed feeding from Android phones to OSM could be continous, expanding the mapped streets exponentially.
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby fabrantes » Mon Sep 29, 2008 12:07 pm

Indeed, does OSM allow this? how do they validate the information introduced... If a validation mechanism would be possible on top of this then it would be perfect :P (something like only adding a street after it has been introduced by two users...)

Cheers
fabrantes
Developer
Developer
 
Posts: 25
Joined: Fri Sep 05, 2008 3:13 pm

Postby ninor » Mon Sep 29, 2008 12:24 pm

There's a validation queue, and some time is required to approve each submission.

Check it here:
http://wiki.openstreetmap.org/index.php/Beginners_Guide_1.2.2
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top

Postby plusminus » Mon Sep 29, 2008 3:47 pm

Yes, Overlays are possible, just like on the MapView (I did not test this, just wrote code for the abstract Overlay and the code to add Overlays to the OpenStreetMapView).

Yes, the uploaded gpx-file gets verified by osm.

I'm still searching for a possibility to get the reliability of the GPS-information Android provides (like satellite count or sth similar). Still no success on that / nobody knows sth. about that. I got told that such information would dramatically improve the benefit from the data.

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby plusminus » Tue Sep 30, 2008 3:31 am

Update:
- MapTile-Filesystem-Cache can now be limited in size (if the size exceeds, tiles get deleted to 90% of max)
- MapTile-Memory-Cache can now be limited in quantity (I'm using LRU-Cache-Strategy here)
- Running Animations can now be stopped at any point in time.
- Overlays are working, just as with the original MapView. See sample:

[align=center]Image Image[/align]

There is currently a common 'bug' or better a problem within the Projection(that is when converting from a GeoPoint to Screencoordinates) in far out zoomed maps:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 /**
  2.  
  3.                  * Converts a GeoPoint to its ScreenCoordinates. <br/>
  4.  
  5.                  * <br/>
  6.  
  7.                  * <b>CAUTION</b> ! Conversion currently has a large error on <code>zoomLevels <= 7</code>.<br/>
  8.  
  9.                  * The Error on ZoomLevels higher than 7, the error is below <code>1px</code>.<br/>
  10.  
  11.                  * TODO: Add a linear interpolation to minimize this error.
  12.  
  13.                  * <PRE>Zoom    Error(m)        Error(px)
  14.  
  15.                  * 11   6m      1/12px
  16.  
  17.                  * 10   24m     1/6px
  18.  
  19.                  * 8    384m    1/2px
  20.  
  21.                  * 6    6144m   3px
  22.  
  23.                  * 4    98304m  10px </PRE>
  24.  
  25.                  * @param in the GeoPoint you want the onScreenCoordinates of.
  26.  
  27.                  * @param reuse just pass null if you do not have a Point to be 'recycled'.
  28.  
  29.                  * @return the Point containing the approximated screencoordinates of the GeoPoint passed.
  30.  
  31.                  */
  32.  
  33.                 public Point toPixels(final GeoPoint in, final Point reuse) {
  34.  
  35.                         // ...
  36.  
  37.                 }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


That is when you have zoomed in that about the half of the united states convers the screen, you have about 5px of error, that is almost not recognizable. But anyway I am working on a interpolation for this.

The first public release will contain a couple of samples to show how easy it is to utilize my OpenStreetMapView.

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby fabrantes » Tue Sep 30, 2008 12:27 pm

Looks awesome, keep it up.
fabrantes
Developer
Developer
 
Posts: 25
Joined: Fri Sep 05, 2008 3:13 pm

Postby ninor » Tue Sep 30, 2008 1:03 pm

plusminus,
Is it so inaccurate that point conversion?
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby plusminus » Tue Sep 30, 2008 1:15 pm

ninor wrote:plusminus,
Is it so inaccurate that point conversion?


The numbers I have posted above are the upper bound of the error. To give you an idea of 'badness' of that error: This is the ZoomLevel, where the error is between 0-5 Pixels:

http://maps.google.com/?ie=UTF8&ll=38.1 ... 43&t=p&z=5

Last night I started working on it but it was to late to get a appropriate result, so I started thinking (pen&paper) about this this morning and I think I've got a good idea for a pretty exact solution.

The problem is that I am currently interpolation linear when I am getting a point within a maptile. But the image on map is not linear, because it uses the so called Mercator-Projection, see the Latitude grow more than linear to the poles:
[align=center]Image[/align]

The closer you get, the better the linear interpolation gets. From zoomlevel on its is subpixel accurate. Also the linear interpolation is much higher performing !

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby plusminus » Wed Oct 01, 2008 5:57 am

I seem to have fixed the projection-error . ('seems' because I have to check if it messed up another part of the code ^^ but it doesn't seem so.)

I added a MiniMap-Feature (see code snippet) that connects two OpenStreetMapViews together. The 'mothermap' and the 'MiniMap' get tied together closely:
  • Panning the MainMap also pans the MiniMap
  • Zooming the MainMap zooms the MiniMap to x-levels less.
  • Panning MiniMap also pans the MainMap, you can pass large distances with a small touch :!:


To give you an experience on what it will look like using my OpenStreetMapView, see this code-snippet. (See the attached image of what it looks like, when its running):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /** Called when the activity is first created. */
  2.  
  3.     @Override
  4.  
  5.     public void onCreate(Bundle savedInstanceState) {
  6.  
  7.         super.onCreate(savedInstanceState);
  8.  
  9.        
  10.  
  11.         final RelativeLayout rl = new RelativeLayout(this);
  12.  
  13.        
  14.  
  15.         /* Create a OpenStreetMapView and add it to the RelativeLayout,
  16.  
  17.          * covering the whole screen. */
  18.  
  19.         this.mOsmv = new OpenStreetMapView(this, OpenStreetMapRendererInfo.MAPNIK);
  20.  
  21.         rl.addView(this.mOsmv, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  22.  
  23.        
  24.  
  25.         /* Create a static Overlay showing a fixed location.
  26.  
  27.          * (Could be updated with the users location)!*/
  28.  
  29.         SimpleLocationOverlay sov = new SimpleLocationOverlay(this);
  30.  
  31.         sov.setLocation(new GeoPoint(40719469,-73998435)); // New York, Manhattan
  32.  
  33.         this.mOsmv.getOverlays().add(sov);    
  34.  
  35.        
  36.  
  37.         /* Create another OpenStreetMapView, that will act as the MiniMap
  38.  
  39.          * for the 'MainMap'. They will share the TileProvider. */
  40.  
  41.         this.mOsmvMinimap = new OpenStreetMapView(this, OpenStreetMapRendererInfo.CLOUDMADESTANDARDTILES, this.mOsmv);
  42.  
  43.         final int aZoomDiff = 3; // Use OpenStreetMapViewConstants.NOT_SET to disable autozooming of this minimap
  44.  
  45.         this.mOsmv.setMiniMap(this.mOsmvMinimap, aZoomDiff);
  46.  
  47.        
  48.  
  49.        
  50.  
  51.         /* Create RelativeLayout.LayoutParams that positions
  52.  
  53.          * the MiniMap on the bottom-right corner of the
  54.  
  55.          * RelativeLayout, just above the 'bigmap'. */
  56.  
  57.         RelativeLayout.LayoutParams minimapParams = new RelativeLayout.LayoutParams(90, 90);
  58.  
  59.         minimapParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  60.  
  61.         minimapParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  62.  
  63.         minimapParams.setMargins(5,5,5,5);
  64.  
  65.         rl.addView(mOsmvMinimap, minimapParams);
  66.  
  67.        
  68.  
  69.         this.setContentView(rl);
  70.  
  71.     }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Attachments
osmv_sample_screen.png
OpenStreetMapView with MiniMap applied.
osmv_sample_screen.png (59.11 KiB) Viewed 48637 times
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby ninor » Wed Oct 01, 2008 7:56 am

This is starting to look like a Professional application! :shock: :)

I'm impatient to test the first betas!
(release date? :roll: )
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby plusminus » Wed Oct 01, 2008 9:44 pm

I'll post an apk soon. Maybe I'll add the example (a bit pimped) as a free version to the AndroidMarket.

:) The minimap in the lower right corner could to be really nice for scrolling with the thumb on an actual device.
:cry: I want to try it out :cry:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby plusminus » Fri Oct 03, 2008 5:56 am

:D Just added support for ItemizedOverlays (similar to the original MapView)

Took me about 1.5 hours without a single run/test and it worked instantly :shock: even as I'm almost falling asleep now :P

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top
Next

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest