• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Map
 

Map

on

  • 236 views

Its explain about the map activity in android, How we can create Google map in android and create an app id with signature.

Its explain about the map activity in android, How we can create Google map in android and create an app id with signature.

Statistics

Views

Total Views
236
Views on SlideShare
236
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Map Map Presentation Transcript

    • l Maps
    • l l l Maps Google Maps API is widely used on the web The Android SDK provides support for easily integrating the Google Maps API
    • l l l Using Google Maps in our apps Configure l Maps require the Google API as the project build target l Maps require a Map API Key in order to be deployed l http://code.google.com/android/add-ons/googleapis/maps-overview.html Code l Create a MapView in a MapActivity l Create Map Overlays
    • l Add Google API in Eclipse • http://developer.android.com/sdk/adding-components.html
    • l l Add Google API in Eclipse Use API 4 for SDK 1.6 – http://developer.android.com/guide/appendix/api-levels.html
    • l l Add Google API in Eclipse Set the Google API as the Project Build Target l Right-click on the project, select Properties
    • l l • l l Keys As we learned in lab 1 section 6, – https://sites.google.com/site/androidappcourse/labs/lab-1 our apps must be signed in order to deploy them on a device Eclipse automatically creates a signed debug keystore that is used when launching our app from Eclipse In order to deploy our app to the public, we must create a signed keystore – See http://developer.android.com/guide/publishing/appsigning.html#ExportWizard
    • l Find your keystore • http://code.google.com/android/add-ons/googleapis/mapkey.html
    • l Find your debug keystore • http://code.google.com/android/add-ons/googleapis/mapkey.html
    • l Get your certificate fingerprint • http://code.google.com/android/add-ons/googleapis/mapkey.html
    • l Register your certificate with Google • http://code.google.com/android/maps-api-signup.html
    • l Add the Map API Key to your Application • <com.google.android.maps.MapView • android:id="@+id/myMap" • android:layout_width="fill_parent" • android:layout_height="fill_parent" • android:clickable="true" • android:apiKey="@string/mapApiKey"/>
    • l l l What’s in the legal agreement? Read the Terms of Service (sections 1-11) l http://code.google.com/android/maps-api-signup.html Examples l Maps may include ads in future l Google may limit number of transactions l Cannot use for turn-by-turn directions or autonomous driving
    • l Configure AndroidManifest.xml • <application android:name="MyApplication" > • <uses-library android:name="com.google.android.maps" /> • ... • </application>
    • l l Finally, we can start coding MapView l Contains a map l via Google Maps API l Map tile retrieval and caching is all done for you l Includes pan l Includes zoom l use setBuiltInZoomControls(true);
    • l l MapActivity MapView can only be constructed or inflated in a MapActivity • public class MyActivity extends MapActivity { •… • @Override • public void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • … • MapView myMap = (MapView)findViewById(R.id.myMap); • myMap.setBuiltInZoomControls(); • myMap.setSatellite(true);
    • l l MapView Modes MapView l You determine mode l setSatellite(true); l setTraffic(true); l setStreetView(true);
    • l l • • • • • • • MapController You can pan and zoom the map programmatically MapView myMap = (MapView)findViewById(R.id.myMap); MapController mapController = myMap.getController(); mapController.setZoom(1); //widest zoom/far away … mapController.setZoom(21); //narrowest zoom/close in mapController.zoomIn(); //one level mapController.zoomOut(); //one level
    • l l GeoPoint You can move to a particular point • • MapView myMap = (MapView)findViewById(R.id.myMap); MapController mapController = myMap.getController(); • • • • • • Double lat = 37.123456 * 1E6; Double long = -122.123456 * 1E6; GeoPoint point = new GeoPoint(lat.intValue(), long.intValue()); mapController.setCenter(point); //jump to point … mapController.animateTo(point); //smooth transition to point
    • l l Reverse Geocoding Find address from longitude/latitude • • • • • • • • • • location = locationManager.getLastKnownLocation( LocationManager.GPS_PROVIDER); double lat = location.getLatitude(); double lng = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); List<Address> addresses = null; try { addresses = gc.getFromLocation(lat, lng, 10); } catch (IOException e) {}
    • l l Forward Geocoding Find longitude/latitude (and more) from address • • • • • • • • Geocoder gc = new Geocoder(this, Locale.US); List<Address> addresses = null; try { addresses = gc.getFromLocationName( “123 Main St., Newton, Kansas”, 10); } catch (IOException e) {} double lat = addresses.get(0).getLatitude(); String zip = addresses.get(0).getPostalCode();
    • l l Geolocation Options l GPS, cell network l Wifi-based l Skyhook Wireless l http://www.skyhookwireless.com/developers/Android_Integration_M anual.php
    • l • • • • • • • • • • • • • • • • • • Setting up location services public MyActivity() { criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); }; private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateWithNewLocation(location); } public void onProviderDisabled(String provider) { updateWithNewLocation(null); } public void onProviderEnabled(String provider) {} public void onStatusChanged(String provider, int status, Bundle extras) {} };
    • • • • • • • • • • • • • • • • • • • • • • • @Override protected void onStart() { super.onStart(); locationManager = (LocationManager)getSystemService( Context.LOCATION_SERVICE); provider = locationManager.getBestProvider(criteria, true); // or could be LocationManager.GPS_PROVIDER try { updateWithNewLocation(locationManager.getLastKnownLocation( provider)); } catch (Exception e) {} locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } private void updateWithNewLocation(Location location) { double latitude = 0.0; double longitude = 0.0; if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); //do something with latitude and longitude (e.g. print or move map there) }
    • l • • • • • • • • • Turn GPS on and off to save battery @Override protected void onPause() { super.onPause(); //stop receiving GPS locationManager.removeUpdates(locationListener); } @Override protected void onResume() { super.onResume(); //restart receiving GPS locationManager.requestLocationUpdates(provider, 2000, 10, • locationListener); • }