integrating open street map in android application

12
IS GOOGLE MAP DEPRECATED? Open Street Map

Upload: ahsanul-karim

Post on 03-Sep-2014

5.787 views

Category:

Technology


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Integrating Open Street Map in Android application

IS GOOGLE MAP DEPRECATED?

Open Street Map

Page 2: Integrating Open Street Map in Android application

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/

Page 3: Integrating Open Street Map in Android application

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.

Page 4: Integrating Open Street Map in Android application

Getting Started

Lets Create a new Project in eclipse.

Page 5: Integrating Open Street Map in Android application

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/Downloadosmdroidandroid104jar.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.

Page 6: Integrating Open Street Map in Android application

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.

Page 7: Integrating Open Street Map in Android application

Add permissions

Add the permissions to the manifest. <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" />

Page 8: Integrating Open Street Map in Android application

Create layout

In main.xml, define the layout:

Page 9: Integrating Open Street Map in Android application

Override onCreate

Now we are ready for some java coding. We Override the onCreate method of MyOpenStreetMapActivity:

Page 10: Integrating Open Street Map in Android application

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.

Page 11: Integrating Open Street Map in Android application

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:

Page 12: Integrating Open Street Map in Android application

Deployment

Now we are ready to run our application.Here we are seeing a button Named “Google Map”. Lets Implement some functionality toIt. Implement a google map to this button which will toggle theMap to google map & shows the user’s current location.