GPS and MapView. First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 4 Overview Overview of Sensors Programming Tutorial 1: Tracking location with GPS and Google.
Advertisements

Google APIs & Location Based Applications -Krishna Achanta
VIP Smartphone Team – Ahmad, Din, Vinayak Car Locator App Fall 2010 VIP Smartphone Team Ahmad, Din, Vinayak.
Customizing the MOSS 2007 Search Results November 2007 Rafael Perez.
GPS and MapView. First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
CS378 - Mobile Computing Maps. Using Google Maps Like other web services requires an API key from Google ons/google-apis/mapkey.html.
Chapter 11: Discover! Incorporating Google Maps
Lecture 13 Mobile Programming Google Maps Android API.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Location & Maps.  Mobile applications can benefit from being location-aware, e.g.,  Routing from a current to a desired location  Searching for stores.
GPS and MapView. First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator.
Android wifi-based localization. Localization types Android allows (location providers) – GPS (GPS_PROVIDER) – Cell tower + wifi (NETWORK_PROVIDER) You.
Location and Maps Content Getting Location Getting Google Map In application Test on Emulator/Device.
Android Development (Basics)
Android Tutorial Larry Walters OOSE Fall References This tutorial is a brief overview of some major concepts…Android is much richer and more complex.
Android Application Development 2013 PClassic Chris Murphy 1.
CS378 - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives: Open Street Maps –
Map Applications.
Android Sensors & Async Callbacks Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
Route Tracker App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Introducing the Sudoku Example
Mobile Application Development Selected Topics – CPIT 490
Google Maps Android API v2 吳俊興 國立高雄大學 資訊工程學系 CSF645 – Mobile Computing 行動計算
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
Social network Twitter Hashtag: #m2eu #android Personal Israel Ferrer –
Location based services
CSS216 MOBILE PROGRAMMING Android, Chapter 8 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse 
Basic Android Tutorial USF’s Association for Computing Machinery.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Android Accessing GPS Ken Nguyen Clayton State University 2012.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
How to publish your app 1 CS440. Step 1: Remove any debug logging  Good practice: comment out any debug logging  Why? CS440 2.
Engage! Android User Input, Variables,
Android Boot Camp for Developers Using Java, 3E
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Location. GPS Global Positioning System – At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within.
Maps Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
First Venture into the Android World Chapter 1 Part 2.
Video Games list lab 6  At the end of this lab you will be expected to know:  What Views, View Groups, Layouts, and Widgets are and how they relate to.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Implementation of Google Map in Drupal Create in Miyula Zeng, XiaoHang Zou,
Sensors – Part 2 SE 395/595. Location in Android LocationManager class – Configure providers and their listeners LocationListener class – Handles update.
Folio3 IPhone Training Session 2 Testing App on device Presenter: Imam Raza.
Cosc 5/4735 YouTube API. YouTube The YouTube Android Player API enables you to incorporate video playback functionality into your Android applications.
Learning the Basics of ArcMap 3.3 Updated 4/27/2010 Using Arc/View pt. 1 1.
CS371m - Mobile Computing Maps. Using Google Maps Content on using Google Maps inside your app Alternatives Exist: – Open Street Maps –
Cosc 5/4730 Support design library. Support Design library Adds (API 9+) back support to a number of 5.0 lollipop widgets and material design pieces –
3 rd -party APIs Kalin Kadiev Astea Solutions AD.
1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.
CS499 – Mobile Application Development Fall 2013 Location & Maps.
Chapter 2: Simplify! The Android User Interface
Android Application Maps 1.
Sensors, maps and fragments:
תכנות ב android אליהו חלסצ'י.
CS371m - Mobile Computing Maps.
Learning the Basics of ArcMap 3.3 Updated 4/27/2010
Working with Libraries
Mobile Programming Dr. Mohsin Ali Memon.
CA16R405 - Mobile Application Development (Theory)
Presentation transcript:

GPS and MapView

First In the emulator, set the time zone to something (e.g., east coast) and check that the time is correct. Otherwise, the gps emulator will not work correctly

plan Show maps Show markers on map Get gps locations Put marker of current location

Get API key Get google maps api key The api key allows you to use the google api The key must be the same as the app key – The eclipse plug in includes a debug key. But when selling apps, you should use your key – For now, we will use the debug key Get the debug certificate – Find where the certificate is Eclipse: menu window->preferences -> android -> build. See field “Default debug keystore:” E.g., c:\documents and settings\stephan\.android\debug.keystore – Get certificate Open cmd shell Go to java jdk directory – E.g., c:\program files\java\jdk1.6.0_18\bin Run – keytool –list –alias androiddebugkey –keystore LOCATION_OF_KEYSTORE –storepass android -keypass android E.g., – keytool –list –alias androiddebugkey –keystore “c:\documents and settings\stephan\.android\debug.keystore“ –storepass android -keypass android – (for some reason, cutting the above into the cmd shell does nto work. It must be typed) The certificate is given: 61:AB:CD:….. Get key from google – Go to – Paste certificate into window – Read and agree to conditions – Select ok – Login with gmail account – Get key

Make view Make new app – ShowMap – Open main.xml – Go to layout view – Add toggle button Change Id to StreetOrSatellite Remove text Add text on “Street“ Add text off “Satellite” – Add map view Open main.xml view (not layout view) Add (note that the key is show here) <com.google.android.maps.MapView android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="0v-E_CPfInuehF9CTgG7o_4JCoAHz3Wbm47EH_g" android:clickable="true"/> Save Check out layout view. – The map view box is shown – Properties are also show

Set permissions and library Open manifest Set permissions – To use the google maps, the internet is needed – Go to permissions tab – Add “User permission” – Set Name to android.permission.INTERNET We’ll need other permissions to use location info – Add “User permission” – Set Name to android.permission.ACCESS_COARSE_LOCATION – Add “User permission” – Set Name to android.permission.ACCESS_FINE_LOCATION – Add “User permission” – Set Name to android.permission.ACCESS_MOCK_LOCATION (I’m not 100% sure about this last one…) Add android maps library – Go to Applications tab – Go to application nodes – Add “Uses Library” – Nsme = com.google.android.maps

Change java code to show map Open ShowMap.java Make activity into MapActivity – Change “extends Activity” to “extends MapActivity” – MapActivity requires isRouteDisplayed be implemented – Near the top (or anyway) protected boolean isRouteDisplayed() { return false; } Run

Add zoom + panning controls Panning – Note: in main.xml we added android:clickable="true“ – This allows pan Zooming – Make reference to MapView object. Add private MapView mapView; As a class attribute near the top of ShowMap class – Set mapView In onCreate add mapView = (MapView)findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); Run

Add toggle for satellite and street view Get reference to toogle button – After mapView.setBuiltInZoomControls(true); – Add final ToggleButton streetViewBtn = (ToggleButton)findViewById(R.id.StreetOrSatellite); After this, set ClickListener streetViewBtn.setOnClickListener(new OnClickListener() public void onClick(View view) { if (streetViewBtn.isChecked()) { mapView.setSatellite(true); mapView.setStreetView(false); } else { mapView.setSatellite(false); mapView.setStreetView(true); } });

Import marker One can draw the marker in the program, or use a drawable resource. We’ll use a drawable resource Import marker – – Right click on image and save as c:\temp\orange_sel_marker.png – Open file explorer and open c:\temp – Drag orange_sel_marker.png to res/drawable-mdpi Add maker object – In ShowMap.java, after streetViewBtn.setOnClickListener – Add Drawable marker = getResources().getDrawable(R.drawable.orange_sel_marker); marker.setBounds(0,0,marker.getIntrinsicWidth(), marker.getIntrinsicHeight());

Add marker to map Marker can take several forms. We will use ItemizedOverlay. These can represent a list of markers However, we must make a class that extends ItemizedOverlay Near the top ShowMap class definition, add – Places places; // Places is our class that extends ItemizedOverlay

Define class Places class Places extends ItemizedOverlay { private List locations = new ArrayList (); private Drawable marker; public Places(Drawable marker) { super(marker); this.marker = marker; GeoPoint UD = new GeoPoint((int)( * ), (int)( * )); GeoPoint home = new GeoPoint((int)( * ), (int)( * )); locations.add(new OverlayItem(UD, "Evans Hall", "EvansHall")); locations.add(new OverlayItem(home, "Home", "Home")); populate(); public void draw(Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, shadow); boundCenterBottom(marker); protected OverlayItem createItem(int i) { return locations.get(i); public int size() { return locations.size(); } After onCreate is complete, add

Attach Places to the map places = new Places(marker, location); mapView.getOverlays().add(places); At the end of onCreate, add run

Add Localization (e..g, GPS) Recall that we have already added permissions Request localization service. In onCreate, just before places = new …, add Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); Next, get service LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); String locInfo = String.format("Initial loc = (%f, (%f meters up)", location.getLatitude(), location.getLongitude(), location.getAltitude() ); Toast.makeText(ShowMap.this, locInfo, Toast.LENGTH_SHORT).show();

Fix location info Toast is too fast Use TextView to display location Go to main.xml Select TextView box Change id Instead of toast… add TextView textView = (TextView)findViewById(R.id.headertext); textView.setText(locInfo); Run

Get location updates For this, we need to define a location listener, which requires making a class that implements LocationListener. After onCreate is defined, add class MyLocationListener implements LocationListener { public void onLocationChanged(Location location) { String locInfo = String.format("Current loc = (%f, (%f meters up)", location.getLatitude(), location.getLongitude(), location.getAltitude() ); Toast.makeText(ShowMap.this, locInfo, Toast.LENGTH_SHORT).show(); } public void onProviderDisabled(String provider) {} public void onProviderEnabled(String provider) {} public void onStatusChanged(String provider, int status, Bundle extras) { } } Set the an object of type MyLocationListener to be the listener. After textView.setText(locInfo); add locationManager.requestLocationUpdates(provider, 1000, 0, new MyLocationListener()); Min time between updates in millsec Min distance in meters between updates RUN

Setting location in the emulator Be sure that the time zone in the emulated phone was set (it is set in settings) In eclipse, in the upper right, select DDMS On the left, select the emulator that is running Below, note “Emulator control” – If emulator control is not there, meun -> window-> show view -> other -> android -> emulator control In emulator control, scroll to Location Control Select Manual tab Enter various values and select send

Put a marker on current location Our Places class has a list of marker locations. We need to add a marker whenever the location listener gets a new location Make a Places function called public void update(Location currentLocation), as follows. At the end of the class Places definition, add public void update(Location currentLocation) { locations.remove(locations.size()-1); // remove oldest GeoPoint current = new GeoPoint((int)(currentLocation.getLatitude()* ), (int)(currentLocation.getLongitude()* )); locations.add(0,new OverlayItem(current, "current", "current")); ShowMap.this.mapView.postInvalidate(); setLastFocusedIndex(-1); populate(); } At the end of MyLocationListener.onLocationChanged, add ShowMap.this.places.update(location); Run and change location with the ddms

Center map around current location At the end of Places.update, add MapController mapControl = ShowMap.this.mapView.getController(); mapControl.animateTo(current);

Make new app, ShowMap Add Open main.xml – Add linear Activity must extend MapActivity