2. Basic Ideas
Open Street Map (OSM) is a free editable map. The
maps are created using data from portable SAT NAV
devices, aerial photography & simply from local
knowledge. The real power of OSM is not default
rendering, but the possibility to actually access the
data behind this map rendering. And this is where it
differs from Google maps, Bing Maps and Yahoo!
Maps and various others. Let’s have a look to OSM at
http://www.openstreetmap.org/
3. Why we are interested?
From 1 January 2012, Google will charge for the
Google Maps API service when more than the limit
of 25,000 map "hits" are made in a day.
Google is rumored to be charging $4 per 1,000 views
in excess of the limit.
These two points may be good enough to make us
interested for hunting a free but reliable option.
5. Getting Started
We have to include two jar files. These are:
1. osmdroid-android-1.04.jar which can be downloaded from
http://www.java2s.com/Code/Jar/o/Downloadosmdroidandr
oid104jar.htm
2. slf4j-android-1.5.8.jar which can
be downloaded from
http://www.slf4j.org/android/
Download the jars by clicking the
links above. Create a folder libs into
the project & put thejars in the
libs folder.
6. Add jars
Add the jars by configuring java build path: Right click on project>Buils Path>
Configure Build Path > Libraries > Add Jars & then select the jars from the
Projects libs folder.
9. Override onCreate
Now we are ready for some java coding. We Override
the onCreate method of MyOpenStreetMapActivity:
10. Analyze onCreate
Lets analyze the onCreate method:
1. We set the content view to main.
2. We initialize the relative layout.
3. We initialize the map view.
4. We add the built in zoom control.
5. We initialize the MyLocationOverlay Class with the
context & mapview.
6. We add the overlay to our map view.
7. We add the map view to our relative layout.
8. We set the zoom level.
11. Override onResume & onPause
We override the onResume Method &
myLocationOverlay is enabled to read the GPS
location:
We override the onPause method to disable the
location listener:
12. Deployment
Now we are ready to run our application.
Here we are seeing a button
Named “Google Map”. Lets
Implement some functionality to
It. Implement a google map to
this button which will toggle the
Map to google map & shows the
user’s current location.