SlideShare una empresa de Scribd logo
1 de 28
Location Based Services
CPE 490/590 Smartphone Programming
by Michael T. Shrove (UAHuntsville)
Things you going to learn in
Android
Displaying Google
Maps
Track location via
GPS or other services.
Displaying Maps
Download Google Play
Services
Google Maps Android API V2 is part of Google’s Play
services SDK, which you must download and
configure to work with your existing Android SDK
installation in Eclipse to use the mapping functions.
In Eclipse, choose Window > Android SDK Manager.
In the list of packages that appears scroll down to
theExtras folder and expand it.
Select the Google Play services checkbox and install
the package.
Import Google Play Services
into your workspace
Once Eclipse downloads and installs the Google Play
services package, you can import it into your workspace.
Select File > Import > Android > Existing Android Code
into Workspace then browse to the location of the
downloaded Google Play services package on your
computer.
It should be inside your downloaded Android SDK directory,
at the following
location:extras/google/google_play_services/libproject/google
-play-services_lib.
Generate API key
To access the Google Maps tools, you need an API
key, which you can obtain through a Google account.
The key is based on your Android app debug or
release certificate.
If you have released apps before, you might have
used the keytool resource to sign them.
In that case, you can use the keystore you generated
at that time to get your API key.
Obtain Google Maps
Android API v2 Key
Navigate to https://code.google.com/apis/console
Create Project
Turn on Google Maps
Android API v2
Select Services from
the list on the left of the
APIs console.
You should see a list of
Google services, scroll
down to Google Maps
Android API V2 and
click to turn it on for
your account.
Create Key
Now we can get a key for the
app.
Select API Access on the
left-hand-side of the API
console.
You may already see a key
for browser apps, but we
need one specifically for
Android apps.
Near the bottom of the page,
select Create new Android
key.
Enter API Information
Enter you
SHA1
certificate
fingerprint
semicolon
Package
name
Include Google Play Services
lib into your project
Although we added the Google Play services package to the
Eclipse workspace, we still need to setup this particular app to
use it.
Select your new project in the Eclipse Package Explorer and
configure its Properties(right-click > Properties or Window >
Properties with the project selected).
Select the Android tab and scroll to the Library section, then
choose Add.
Select the Google Play Services library to add it to your
project.
Manifest Changes
Add the below changes to the manifest before
application tag.
Add key to manifest
Add the api key to your application tag in the
manifest.
Add the map to the app
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/the_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
map:cameraTilt="45"
map:cameraZoom="14" />
GPS
Create the Classes
Create a LocationManager
Create a LocationListener
Location Manager
What is a Location Manager?
This class provides access to the system
location services.
These services allow applications to obtain
periodic updates of the device's geographical
location, or to fire an application-specified
Intent when the device enters the proximity of a
given geographical location.
Location Listener
What is a Location Listener?
Used for receiving notifications from the
LocationManager when the location has changed.
These methods are called if the LocationListener
has been registered with the location manager
service using the requestLocationUpdates(String,
long, float, LocationListener) method.
Location Strategies
Knowing where the user is allows your application to be smarter and
deliver better information to the user.
When developing a location-aware application for Android, you can utilize
GPS and Android's Network Location Provider to acquire the user location.
Although GPS is most accurate, it only works outdoors, it quickly consumes
battery power, and doesn't return the location as quickly as users want.
Android's Network Location Provider determines user location using cell
tower and Wi-Fi signals, providing location information in a way that works
indoors and outdoors, responds faster, and uses less battery power.
To obtain the user location in your application, you can use both GPS and
the Network Location Provider, or just one.
Example of Obtaining User
Location
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
Edit the
AndroidManifest.xml
<uses-sdk android:minSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:icon="@drawable/ic_launcher"
android:label="Where Am I" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="@string/app_name"
android:name=".LBSActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Getting a fast fix with the
last known location
String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or use LocationManager.GPS_PROVIDER
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
Stop listening for updates
// Remove the listener you previously added
locationManager.removeUpdates(locationListener);
iOS
Adding a Map
Add the MapKit framework to your project
Drag and Drop MKMapView onto your view.
Drink Coffee!
Example of Adding MapKit
framework
Example of
LocationManager
https://github.com/vandadnp/iOS-8-Swift-Programming-
Cookbook/blob/master/chapter-
maps/Pinpointing%20the%20Location%20of%20a%20
Device/Pinpointing%20the%20Location%20of%20a%2
0Device/ViewController.swift

Más contenido relacionado

La actualidad más candente

iOS-iPhone documentation
iOS-iPhone documentationiOS-iPhone documentation
iOS-iPhone documentation
Raj Dubey
 
White paper native, web or hybrid mobile app development
White paper  native, web or hybrid mobile app developmentWhite paper  native, web or hybrid mobile app development
White paper native, web or hybrid mobile app development
IBM Software India
 

La actualidad más candente (20)

What To Choose Between - Native App And Hybrid Mobile App
What To Choose Between - Native App And Hybrid Mobile AppWhat To Choose Between - Native App And Hybrid Mobile App
What To Choose Between - Native App And Hybrid Mobile App
 
Presentation
PresentationPresentation
Presentation
 
Mobility testing day_1_ppt
Mobility testing day_1_pptMobility testing day_1_ppt
Mobility testing day_1_ppt
 
Flutter single codebase to build your dream application for i os and android
Flutter single codebase to build your dream application for i os and android Flutter single codebase to build your dream application for i os and android
Flutter single codebase to build your dream application for i os and android
 
iOS-iPhone documentation
iOS-iPhone documentationiOS-iPhone documentation
iOS-iPhone documentation
 
Native script vs react native for native app development in 2022
Native script vs react native for native app development in 2022Native script vs react native for native app development in 2022
Native script vs react native for native app development in 2022
 
Flutter 2.2 version | skywave info solutions
Flutter 2.2 version | skywave info solutionsFlutter 2.2 version | skywave info solutions
Flutter 2.2 version | skywave info solutions
 
Find the right mobile app architecture for your business [detailed guide]
Find the right mobile app architecture for your business [detailed guide]Find the right mobile app architecture for your business [detailed guide]
Find the right mobile app architecture for your business [detailed guide]
 
Best cross platform app development frameworks for 2021
Best cross platform app development frameworks for 2021Best cross platform app development frameworks for 2021
Best cross platform app development frameworks for 2021
 
Ionic vs flutter best platform for hybrid app development
Ionic vs flutter  best platform for hybrid app developmentIonic vs flutter  best platform for hybrid app development
Ionic vs flutter best platform for hybrid app development
 
Mobile App Development for Dummies
Mobile App Development for DummiesMobile App Development for Dummies
Mobile App Development for Dummies
 
Everything you need to know about native application development
Everything you need to know about native application developmentEverything you need to know about native application development
Everything you need to know about native application development
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
Why react native has become the winning choice for cross platform development
Why react native has become the winning choice for cross platform developmentWhy react native has become the winning choice for cross platform development
Why react native has become the winning choice for cross platform development
 
IRJET- Cross Platform User Compatible System with Specific Application
IRJET- Cross Platform User Compatible System with Specific ApplicationIRJET- Cross Platform User Compatible System with Specific Application
IRJET- Cross Platform User Compatible System with Specific Application
 
Internship presentation
Internship presentationInternship presentation
Internship presentation
 
Web Application Development Tools for Creating Perfect User Experience
Web Application Development Tools for Creating Perfect User ExperienceWeb Application Development Tools for Creating Perfect User Experience
Web Application Development Tools for Creating Perfect User Experience
 
Here are the Most Useful Tools for Mobile App Development
Here are the Most Useful Tools for Mobile App DevelopmentHere are the Most Useful Tools for Mobile App Development
Here are the Most Useful Tools for Mobile App Development
 
White paper native, web or hybrid mobile app development
White paper  native, web or hybrid mobile app developmentWhite paper  native, web or hybrid mobile app development
White paper native, web or hybrid mobile app development
 
Hybrid mobile app development
Hybrid mobile app developmentHybrid mobile app development
Hybrid mobile app development
 

Similar a Location based services 10

Android tutorial ppt
Android tutorial pptAndroid tutorial ppt
Android tutorial ppt
Rehna Renu
 
Android App Development 04 : Location API
Android App Development 04 : Location APIAndroid App Development 04 : Location API
Android App Development 04 : Location API
Anuchit Chalothorn
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
NgLQun
 
Introduction to Android Development Latest
Introduction to Android Development LatestIntroduction to Android Development Latest
Introduction to Android Development Latest
Prof. Erwin Globio
 

Similar a Location based services 10 (20)

How To Build and Deploy Android App Bundles.pdf
How To Build and Deploy Android App Bundles.pdfHow To Build and Deploy Android App Bundles.pdf
How To Build and Deploy Android App Bundles.pdf
 
MAD Unit 6.pptx
MAD Unit 6.pptxMAD Unit 6.pptx
MAD Unit 6.pptx
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial ppt
Android tutorial pptAndroid tutorial ppt
Android tutorial ppt
 
Android App Development 04 : Location API
Android App Development 04 : Location APIAndroid App Development 04 : Location API
Android App Development 04 : Location API
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
 
Java Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development WorkshopJava Meetup - 12-03-15 - Android Development Workshop
Java Meetup - 12-03-15 - Android Development Workshop
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspective
 
Final NEWS.pdf
Final NEWS.pdfFinal NEWS.pdf
Final NEWS.pdf
 
Final NewsApp.pdf
Final NewsApp.pdfFinal NewsApp.pdf
Final NewsApp.pdf
 
Google Location Services
Google Location ServicesGoogle Location Services
Google Location Services
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services
 
Introduction to Android Development Latest
Introduction to Android Development LatestIntroduction to Android Development Latest
Introduction to Android Development Latest
 
Methods to set up android app development environment
Methods to set up android app development environmentMethods to set up android app development environment
Methods to set up android app development environment
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 

Más de Michael Shrove

Más de Michael Shrove (8)

Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)
 
Ui 5
Ui   5Ui   5
Ui 5
 
Swift 3
Swift   3Swift   3
Swift 3
 
Sensors 9
Sensors   9Sensors   9
Sensors 9
 
Storage 8
Storage   8Storage   8
Storage 8
 
Java 2
Java   2Java   2
Java 2
 
Course overview 1
Course overview   1Course overview   1
Course overview 1
 
Basics 4
Basics   4Basics   4
Basics 4
 

Location based services 10

  • 1. Location Based Services CPE 490/590 Smartphone Programming by Michael T. Shrove (UAHuntsville)
  • 2. Things you going to learn in Android Displaying Google Maps Track location via GPS or other services.
  • 4. Download Google Play Services Google Maps Android API V2 is part of Google’s Play services SDK, which you must download and configure to work with your existing Android SDK installation in Eclipse to use the mapping functions. In Eclipse, choose Window > Android SDK Manager. In the list of packages that appears scroll down to theExtras folder and expand it. Select the Google Play services checkbox and install the package.
  • 5. Import Google Play Services into your workspace Once Eclipse downloads and installs the Google Play services package, you can import it into your workspace. Select File > Import > Android > Existing Android Code into Workspace then browse to the location of the downloaded Google Play services package on your computer. It should be inside your downloaded Android SDK directory, at the following location:extras/google/google_play_services/libproject/google -play-services_lib.
  • 6. Generate API key To access the Google Maps tools, you need an API key, which you can obtain through a Google account. The key is based on your Android app debug or release certificate. If you have released apps before, you might have used the keytool resource to sign them. In that case, you can use the keystore you generated at that time to get your API key.
  • 7. Obtain Google Maps Android API v2 Key Navigate to https://code.google.com/apis/console
  • 9. Turn on Google Maps Android API v2 Select Services from the list on the left of the APIs console. You should see a list of Google services, scroll down to Google Maps Android API V2 and click to turn it on for your account.
  • 10. Create Key Now we can get a key for the app. Select API Access on the left-hand-side of the API console. You may already see a key for browser apps, but we need one specifically for Android apps. Near the bottom of the page, select Create new Android key.
  • 11. Enter API Information Enter you SHA1 certificate fingerprint semicolon Package name
  • 12. Include Google Play Services lib into your project Although we added the Google Play services package to the Eclipse workspace, we still need to setup this particular app to use it. Select your new project in the Eclipse Package Explorer and configure its Properties(right-click > Properties or Window > Properties with the project selected). Select the Android tab and scroll to the Library section, then choose Add. Select the Google Play Services library to add it to your project.
  • 13. Manifest Changes Add the below changes to the manifest before application tag.
  • 14. Add key to manifest Add the api key to your application tag in the manifest.
  • 15. Add the map to the app <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:id="@+id/the_map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment" map:cameraTilt="45" map:cameraZoom="14" />
  • 16. GPS
  • 17. Create the Classes Create a LocationManager Create a LocationListener
  • 18. Location Manager What is a Location Manager? This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to fire an application-specified Intent when the device enters the proximity of a given geographical location.
  • 19. Location Listener What is a Location Listener? Used for receiving notifications from the LocationManager when the location has changed. These methods are called if the LocationListener has been registered with the location manager service using the requestLocationUpdates(String, long, float, LocationListener) method.
  • 20. Location Strategies Knowing where the user is allows your application to be smarter and deliver better information to the user. When developing a location-aware application for Android, you can utilize GPS and Android's Network Location Provider to acquire the user location. Although GPS is most accurate, it only works outdoors, it quickly consumes battery power, and doesn't return the location as quickly as users want. Android's Network Location Provider determines user location using cell tower and Wi-Fi signals, providing location information in a way that works indoors and outdoors, responds faster, and uses less battery power. To obtain the user location in your application, you can use both GPS and the Network Location Provider, or just one.
  • 21. Example of Obtaining User Location // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  • 22. Edit the AndroidManifest.xml <uses-sdk android:minSdkVersion="13" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <application android:icon="@drawable/ic_launcher" android:label="Where Am I" > <uses-library android:name="com.google.android.maps" /> <activity android:label="@string/app_name" android:name=".LBSActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
  • 23. Getting a fast fix with the last known location String locationProvider = LocationManager.NETWORK_PROVIDER; // Or use LocationManager.GPS_PROVIDER Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
  • 24. Stop listening for updates // Remove the listener you previously added locationManager.removeUpdates(locationListener);
  • 25. iOS
  • 26. Adding a Map Add the MapKit framework to your project Drag and Drop MKMapView onto your view. Drink Coffee!
  • 27. Example of Adding MapKit framework