OpenStreetMap MapView for Android

Tutorials that use the MapActivity. Many using GPS functionality.

Postby ninor » Fri Oct 03, 2008 10:07 am

:shock: :o :shock:

When will you release it!? - When will you release it!? - When will you release it!? :lol:
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top

Postby plusminus » Fri Oct 03, 2008 1:16 pm

:lol: Soon, soon :P

Let me strengthen the excitement with this screenshot :darrow: it shows an ItemizedOverlay with the default marker.

This is the code. (Create a List of Overlayitems, create a overlay with these items and a taplistener, add the overlay to the OSMapView, Done) :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /* Create a static ItemizedOverlay showing a some Markers on some cities. */
  2.  
  3. ArrayList<OpenStreetMapViewOverlayItem> items = new ArrayList<OpenStreetMapViewOverlayItem>();
  4.  
  5. items.add(new OpenStreetMapViewOverlayItem("Hannover", "SampleDescription", new GeoPoint(52370816, 9735936))); // Hannover
  6.  
  7. items.add(new OpenStreetMapViewOverlayItem("Berlin", "SampleDescription", new GeoPoint(52518333, 13408333))); // Berlin  
  8.  
  9. items.add(new OpenStreetMapViewOverlayItem("Washington", "SampleDescription", new GeoPoint(38895000, -77036667))); // Washington
  10.  
  11. items.add(new OpenStreetMapViewOverlayItem("San Francisco", "SampleDescription", new GeoPoint(37779300, -122419200))); // San Francisco
  12.  
  13.        
  14.  
  15. /* OnTapListener for the Markers, shows a simpel Toast. */
  16.  
  17. this.mMyLocationOverlay = new OpenStreetMapViewItemizedOverlay<OpenStreetMapViewOverlayItem>(this, items, new OpenStreetMapViewItemizedOverlay.OnItemTapListener<OpenStreetMapViewOverlayItem>(){
  18.  
  19.         @Override
  20.  
  21.         public boolean onItemTap(int index, OpenStreetMapViewOverlayItem item) {
  22.  
  23.                 Toast.makeText(SampleWithMinimapItemizedoverlay.this, "Item '" + item.mTitle + "' (index=" + index + ") got tapped", Toast.LENGTH_LONG).show();
  24.  
  25.                 return true; // We 'handled' this event.
  26.  
  27.         }
  28.  
  29. });
  30.  
  31. this.mOsmv.getOverlays().add(this.mMyLocationOverlay);  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Attachments
itemizedoverlay_sample.png
itemizedoverlay_sample.png (28.96 KiB) Viewed 8840 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 » Fri Oct 03, 2008 3:28 pm

That's really only a handful lines!
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby plusminus » Sat Oct 04, 2008 12:33 am

ninor wrote:That's really only a handful lines!


I now added some sample code to add ZoomControls overlayed on the map.

Next feature will be to make one item of the ItemizedOverlay 'focusable', what means showing Title and Message.

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 » Sat Oct 04, 2008 7:33 am

Created a Class, extending the Itemized Overlay, which can show a Desciption/Title of a tapped item, like when you ...
Its hard to explain, so simply see the screenshot :darrow: ;)

Its not yet finished (problems that other markers Overlay the description-'window', also words are broken in the middle.

Regards,
plusminus
Attachments
ItemizedOverlayWithFocus_sample.png
ItemizedOverlayWithFocus_sample.png (21.72 KiB) Viewed 8788 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 plusminus » Sat Oct 04, 2008 3:44 pm

ItemizedOverlayWithFocus is done :)
Attachments
ItemizedOverlayWithFocus_sample_2.png
ItemizedOverlayWithFocus_sample_2.png (25.32 KiB) Viewed 8767 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

Top

Postby ninor » Sun Oct 05, 2008 12:19 am

This will be even better than the MapView itself!
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby Marchu » Mon Oct 06, 2008 12:34 am

plusminus wrote:
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


Hello Plusminus,

Just some thought and maybe you have found allready a solution.

Why not using the normal raw NMEA sentence?
You can get i directly from the GPS and calculate the DOP (dilution of precision).
Besides that, you can also calculate the amount of enough satelites and more this way.
I.e.
$GPGSA,A,3,11,29,07,08,5,17,24,,,,,,2.3,1.2,2.0*30

The bold are representing mean, horizontal and vertical DOP.
The lower the DOP the better.

Some tabel of DOP values (not made by me)
1 - Ideal This is the highest possible confidence level to be used for applications demanding the highest possible precision at all times.
2-3 - Excellent At this confidence level, positional measurements are considered accurate enough to meet all but the most sensitive applications.
4-6 - Good Represents a level that marks the minimum appropriate for making business decisions. Positional measurements could be used to make reliable in-route navigation suggestions to the user.
7-8 - Moderate Positional measurements could be used for calculations, but the fix quality could still be improved. A more open view of the sky is recommended.
9-20 - Fair Represents a low confidence level. Positional measurements should be discarded or used only to indicate a very rough estimate of the current location.
21-50 - Poor At this level, measurements are inaccurate by as much as half a football field and should be discarded.

Like a said maybe you know this allready.
I have not used java for a couple of years (but picking it up), so i not know at the moment how you can manage this in java.
But i am a pro programmer in other languages, and have used this in windows mobile enviroment (C# asp.net).
The only thing you need to do is get the nmea senteces (every couple of seconds), and make a parser and interpreter to get the values.

Just my 2 cents :)

Cheers
Last edited by Marchu on Mon Oct 06, 2008 2:21 am, edited 2 times in total.
Marchu
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Sep 27, 2008 4:11 pm
Location: Netherlands

Postby MrSnowflake » Mon Oct 06, 2008 12:56 am

Just a question, as I didn't look at GoogleMaps doc. But can't you use the Overlays from the GoogleMapsView?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby plusminus » Mon Oct 06, 2008 1:00 am

Marchu wrote:
plusminus wrote:
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


Hello Plusminus,

Just some thought and maybe you have found allready a solution.

Why not using the normal raw NMEA sentence?
You can get i directly from the GPS and calculate the DOP (dilution of precision).
Besides that, you can also calculate the amount of enough satelites and more this way.
I.e.
$GPGSA,A,3,11,29,07,08,5,17,24,,,,,,2.3,1.2,2.0*30

The bold are representing mean, horizontal and vertical DOP.
The lower the DOP the better.

Some tabel of DOP values (not made by me)
1 - Ideal This is the highest possible confidence level to be used for applications demanding the highest possible precision at all times.
2-3 - Excellent At this confidence level, positional measurements are considered accurate enough to meet all but the most sensitive applications.
4-6 - Good Represents a level that marks the minimum appropriate for making business decisions. Positional measurements could be used to make reliable in-route navigation suggestions to the user.
7-8 - Moderate Positional measurements could be used for calculations, but the fix quality could still be improved. A more open view of the sky is recommended.
9-20 - Fair Represents a low confidence level. Positional measurements should be discarded or used only to indicate a very rough estimate of the current location.
21-50 - Poor At this level, measurements are inaccurate by as much as half a football field and should be discarded.

Like a said maybe you know this allready.
I have not used java for a couple of years (but picking it up), so i not know at the moment how you can manage this in java.
But i am a pro programmer in other languages, and have used this in windows mobile enviroment (C# asp.net).
The only thing you need to do is get the nmea senteces (every couple of seconds), and make a parser and interpreter to get the values.

Just my 2 cents :)

Cheers


Android abstracts a lot, so I cannot access (or at least haven't seen a possibility to do so) the raw data :(

MrSnowflake wrote:Just a question, as I didn't look at GoogleMaps doc. But can't you use the Overlays from the GoogleMapsView?


No because then the user would have to include the maps package. BUT 99% of your code would stay the same :!:

Anyway, I attach the current (unsigned) apk :)
Attachments
OpenStreetMapViewer.apk
Preview version of OpenStreetMapView with Samples.
(60.4 KiB) Downloaded 518 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 » Mon Oct 06, 2008 9:27 am

ADB is reporting that it must be signed..

Q? Can be signed a "solo" APK :?:
(That is, a standalone APK without having the code)
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Postby plusminus » Mon Oct 06, 2008 2:03 pm

ninor wrote:ADB is reporting that it must be signed..

Q? Can be signed a "solo" APK :?:
(That is, a standalone APK without having the code)


Damn, up to now i never had a look at the signing stuff...
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 Oct 07, 2008 3:46 am

Second try :D signed apk attached.

[Edit]
Now the correct apk xD.
[/Edit]

If it works, I'll post the steps needed as a tutorial.

Best Regards,
plusminus
Attachments
OpenStreetMapViewer_signed.apk
(64.57 KiB) Downloaded 432 times
Last edited by plusminus on Wed Oct 08, 2008 2:22 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

Postby plusminus » Tue Oct 07, 2008 6:30 am

Just added a couple of different Animation-Types, what means the developer can choose from the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /**
  2.  
  3.          * Choose on of the Styles of approacing the target Coordinates.
  4.  
  5.          * <ul>
  6.  
  7.          * <li><code>LINEAR</code>
  8.  
  9.          *      <ul>
  10.  
  11.          *              <li>Uses ses linear interpolation </li>
  12.  
  13.          *              <li>Values produced: 10%, 20%, 30%, 40%, 50%, ...</li>
  14.  
  15.          *              <li>Style: Always average speed.</li>
  16.  
  17.          *      </ul>
  18.  
  19.          * </li>
  20.  
  21.          * <li><code>EXPONENTIALDECELERATING</code>
  22.  
  23.          *      <ul>
  24.  
  25.          *              <li>Uses a exponential interpolation/li>
  26.  
  27.          *              <li>Values produced: 50%, 75%, 87.5%, 93.5%, ...</li>
  28.  
  29.          *              <li>Style: Starts very fast, really slow in the end.</li>
  30.  
  31.          *      </ul>
  32.  
  33.          * </li>
  34.  
  35.          * <li><code>QUARTERCOSINUSALDECELERATING</code>
  36.  
  37.          *      <ul>
  38.  
  39.          *              <li>Uses the first quarter of the cos curve (from zero to PI/2) for interpolation. </li>
  40.  
  41.          *              <li>Values produced: See cos curve <img src="http://www.anddev.org/images/smilies/smile.png" alt=":)" title="Smile" /></li>
  42.  
  43.          *              <li>Style: Average speed, slows out medium.</li>
  44.  
  45.          *      </ul>
  46.  
  47.          * </li>
  48.  
  49.          * <li><code>HALFCOSINUSALDECELERATING</code>
  50.  
  51.          *      <ul>
  52.  
  53.          *              <li>Uses the first half of the cos curve (from zero to PI) for interpolation</li>
  54.  
  55.          *              <li>Values produced: See cos curve <img src="http://www.anddev.org/images/smilies/smile.png" alt=":)" title="Smile" /></li>
  56.  
  57.          *              <li>Style: Average speed, slows out smoothly.</li>
  58.  
  59.          *      </ul>
  60.  
  61.          * </li>
  62.  
  63.          * <li><code>MIDDLEPEAKSPEED</code>
  64.  
  65.          *      <ul>
  66.  
  67.          *              <li>Uses the values of cos around the 0 (from -PI/2 to +PI/2) for interpolation</li>
  68.  
  69.          *              <li>Values produced: See cos curve <img src="http://www.anddev.org/images/smilies/smile.png" alt=":)" title="Smile" /></li>
  70.  
  71.          *              <li>Style: Starts medium, speeds high in middle, slows out medium.</li>
  72.  
  73.          *      </ul>
  74.  
  75.          * </li>
  76.  
  77.          * </ul>
  78.  
  79.          */
  80.  
  81.         public static enum AnimationType {
  82.  
  83.                 LINEAR,
  84.  
  85.                 EXPONENTIALDECELERATING,
  86.  
  87.                 QUARTERCOSINUSALDECELERATING,
  88.  
  89.                 HALFCOSINUSALDECELERATING,
  90.  
  91.                 MIDDLEPEAKSPEED;
  92.  
  93.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Attachments
cosine.png
Watch this picture to see what I mean, when I'm talking of from -PI/2 to PI/2 ...
cosine.png (6.62 KiB) Viewed 8605 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 » Tue Oct 07, 2008 4:26 pm

It worked!

E:\android\android-sdk-windows-1.0_r1\tools>adb install AndOpenStreetMap_signed.apk
1111 KB/s (0 bytes in 17777.000s)
pkg: /data/local/tmp/AndOpenStreetMap_signed.apk
Success
Attachments
OpenStreetMapView.jpg
OpenStreetMapView.jpg (30.94 KiB) Viewed 8567 times
Image AndDev: Your Android Development Community / Tutorials | Here's my Basic ToolKit
User avatar
ninor
Moderator
Moderator
 
Posts: 180
Joined: Thu Aug 14, 2008 6:30 pm
Location: Barcelona, Spain

Top
PreviousNext

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests