Maps in android

763 views 12 slides Sep 14, 2016
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

How Maps are created in Android Apps? Basic functions are described here.


Slide Content

MAPS IN ANDROID By- Sumita Das Copyright © Sumita Das All Rights Reserved

Android allows us to integrate Google maps in our application. Customize the map according to your choices. Introduction Copyright © Sumita Das All Rights Reserved

S everal classes that are used to support Android maps: MapView : U ser interface element that displays the map. MapActivity : Base class used to create an Activity that can include a Map View. Overlay : Class used to annotate your maps MapController : U sed to control the map, and enables the user to set the center location and zoom levels. MyLocationOverlay : Can be used to display the current position and orientation of the device. Introducing Map View and Map Activity Copyright © Sumita Das All Rights Reserved

Obtain an API key from the Android developer website at http://code.google.com/android/maps-api-signup.html . To obtain a key, you need to specify the MD5 fingerprint of the certificate used to sign your application. . Getting Your Maps API Key Copyright © Sumita Das All Rights Reserved

To use maps- extend MapActivity . The layout for the new class must then include a MapView to display a Google Maps interface element. Android maps library - optional API. So it must be explicitly included in the application manifest before it can be used. Creating a Map-Based Activity <uses-library android:name=” com.google.android.maps ”/> Copyright © Sumita Das All Rights Reserved

Map View : -Downloads its map tiles on demand - Any application that features a Map View needs to include a uses-permission for Internet access. Add a uses-permission tag to your application manifest for INTERNET, as shown here : After adding the library and configuring your permission, you’re ready to create your new map-based Activity. Creating a Map-Based Activity <uses-permission android:name=”android.permission.INTERNET”/> Copyright © Sumita Das All Rights Reserved

A map Activity layout resource <?xml version=”1.0” encoding=”utf-8”?> < LinearLayout xmlns:android =”http://schemas.android.com/apk/res/android” android:orientation =”vertical” android:layout_width =” fill_parent ” android:layout_height =” fill_parent ”> < com.google.android.maps.MapView android:id =”@+id/ map_view ” android:layout_width =” fill_parent ” android:layout_height =” fill_parent ” android:enabled =”true” android:clickable =”true” android:apiKey =” mymapapikey ”/> </ LinearLayout > Copyright © Sumita Das All Rights Reserved

Framework for creating a new map-based Activity. import com.google.android.maps.MapActivity ; // import classes import com.google.android.maps.MapController ; import com.google.android.maps.MapView ; import android.os.Bundle ; public class MyMapActivity extends MapActivity { private MapView mapView ; private MapController mapController ; @Override public void onCreate (Bundle savedInstanceState ) { super.onCreate ( savedInstanceState ); setContentView ( R.layout.map_layout ); mapView = ( MapView ) findViewById ( R.id.map_view ); } @Override protected boolean isRouteDisplayed () { // IMPORTANT: This method must return true if your Activity is displaying driving directions. Otherwise return false. return false; }} Copyright © Sumita Das All Rights Reserved

Example of a basic map-based Activity Copyright © Sumita Das All Rights Reserved

1. To display a satellite view and the expected traffic overlay: mapView.setSatellite (true); mapView.setTraffic (true); 2. To find the current and maximum available zoom levels: int maxZoom = mapView.getMaxZoomLevel (); int currentZoom = mapView.getZoomLevel (); Configuring and Using Map Views Copyright © Sumita Das All Rights Reserved

3. To obtain center point and currently visible longitude and latitude span (in decimal degrees). GeoPoint center = mapView.getMapCenter (); int latSpan = mapView.getLatitudeSpan (); int longSpan = mapView.getLongitudeSpan (); Copyright © Sumita Das All Rights Reserved

[1]Wei- Meng Lee, “Beginning Android Application Development”, Wiley Publishing Inc. Copyright © Sumita Das All Rights Reserved