Unformatted text preview:

CS 696 Mobile Phone Application DevelopmentFall Semester, 2009Doc 9 Location & MapsSept 29, 2009Copyright ©, All rights reserved. 2009 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent (http://www.opencontent.org/opl.shtml) license defines the copyright on this document.References2MapView tutorial, http://developer.android.com/guide/tutorials/views/hello-mapview.htmlGoogleMaps with Geocoder Class, http://www.anddev.org/simple_googlemaps_geocoder_-_convert_address_to_lon-lat-t2936.htmlSimple GoogleMaps with Threads http://www.anddev.org/simple_googlemaps_with_threads-t2943.htmlThe Busy Coder's Guide to Android Development, V2.1, Mark L. MurphyLocation332° 46' 29.9994" -117° 4' 13.0008"32.775 -117.07027832775000 -117070278LatitudeLongitude* 1000000Geo Coders4Map Address to latitude & longitudeAndroid Geocoder5Geocoder campus = new Geocoder(this); String addressInput = "5500 Campanile Drive, San Diego CA"; try { int maxResults = 3;List<Address> foundAdresses;foundAdresses = campus.getFromLocationName(addressInput, maxResults);for (int i = 0; i < foundAdresses.size(); ++i) { Address x = foundAdresses.get(i); double latitude = x.getLatitude(); double longitude = x.getLongitude(); } } catch (Exception e) { blah } If you get multiple result back you should ask the user which one is correct.Don't forget to multiple by latitude and longitude by 1000000 to convert it to an integer.Android Maps - Add-on6http://code.google.com/android/add-ons/google-apis/index.htmlMark Murphy7"Google Maps, particularly when integrated into third party applications, requires agreeing to a fairly lengthy set of legal terms. These terms include clauses that you may find unpalatable."The Busy Coder's Guide to Android Development, V2.1, Mark L. Murphy page 399First Map Example8Marker on GMCSMapActivity9public class MapExample extends MapActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout linearLayout = (LinearLayout) findViewById(R.id.zoomview); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker); HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(drawable); GeoPoint gmcs = new GeoPoint(32776389, -117069167); OverlayItem overlayitem = new OverlayItem(gmcs, "GMCS", "This is where the Computer Science department is located at SDSU"); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); } protected boolean isRouteDisplayed() { return false; }}How to add png graphic to Project10Just add it to the res/drawable directoryOverlay11public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> { private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>(); public HelloItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); } public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); } protected OverlayItem createItem(int i) { return mOverlays.get(i); } public int size() { return mOverlays.size(); }}Main XML 12<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainlayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="0EqsdoMWNHdDiPF9uHOYe-KJG328jz2ZpsfTUMg" /><LinearLayout android:id="@+id/zoomview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/mapview" android:layout_centerHorizontal="true"/></RelativeLayout>Map Keys13http://code.google.com/android/add-ons/google-apis/mapkey.htmlYou need a map key to use Google Mapskeytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass androidGenerate certificate fingerprintGenerate keyhttp://code.google.com/android/add-ons/google-apis/maps-api-signup.htmlDebug Certificate14Good for one yearPermissions15<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="edu.sdsu.cs696" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MapExample" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="com.google.android.maps" /> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.INTERNET" /></manifest>Zoom, Centering & Satellite 16Map Example Again17public class MapExample extends MapActivity { MapView mapView; HelloItemizedOverlay itemizedOverlay; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); setGMCSOverlay(); }Centering & set Zoom level18 private void setGMCSOverlay() { mapView.setBuiltInZoomControls(true); List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable( R.drawable.androidmarker); itemizedOverlay = new HelloItemizedOverlay(this, drawable); GeoPoint gmcs = new GeoPoint(32776389, -117069167); OverlayItem overlayitem = new OverlayItem(gmcs, "GMCS", "This is where the Computer Science department is located at SDSU"); itemizedOverlay.addOverlay(overlayitem); mapOverlays.add(itemizedOverlay); MapController controls = mapView.getController(); controls.setZoom(16); controls.setCenter(gmcs); }Handling Key Down19 public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_S) { mapView.setSatellite(!mapView.isSatellite()); return (true); } return (super.onKeyDown(keyCode, event)); }Multiple Locations, My


View Full Document

SDSU CS 696 - Location & Maps

Download Location & Maps
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Location & Maps and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Location & Maps 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?