SlideShare a Scribd company logo
Android	
  Loca+on	
  and	
  Maps	
  

         Jussi	
  Pohjolainen	
  
Loca+on	
  Services	
  and	
  Maps	
  
•  Android	
  provides	
  loca+on	
  framework	
  that	
  
   your	
  app	
  can	
  use	
  to	
  determine	
  	
  
   –  Device’s	
  loca+on	
  
   –  Listening	
  for	
  updates	
  
•  Google	
  maps	
  external	
  library	
  available	
  for	
  
   displaying	
  and	
  managing	
  maps	
  
LOCATION	
  SERVICES	
  
Loca+on	
  Services	
  
•  By	
  using	
  Loca+onManager	
  you	
  are	
  able	
  to	
  
   –  Query	
  for	
  the	
  list	
  of	
  Loca+onProviders	
  for	
  the	
  last	
  
      known	
  loca+on	
  
   –  Register	
  for	
  updates	
  of	
  the	
  user’s	
  current	
  loca+on	
  
   –  Register	
  for	
  given	
  Intent	
  to	
  be	
  fired	
  if	
  the	
  device	
  
      comes	
  within	
  given	
  proximity	
  of	
  given	
  lat/long	
  
Obtaining	
  User	
  Loca+on	
  
•  Loca+on	
  can	
  be	
  determined	
  via	
  GPS	
  and/or	
  
     cell	
  tower	
  +	
  Wi-­‐Fi	
  signals	
  
•  GPS	
  is	
  accurate,	
  but	
  needs	
  outdoors,	
  fix	
  is	
  
     slower	
  and	
  it	
  uses	
  more	
  baQery.	
  	
  
•  To	
  request	
  loca+on,	
  you	
  use	
  Loca+onManager	
  
     -­‐	
  class	
  
	
  
Reques+ng	
  Loca+on	
  Updates	
  
                          Can	
  be	
  also	
  
                         GPS_PROVIDER	
  
                                                    Control	
  
                                                       the	
  
                                                  frequency	
  
                                                     which	
  
                                                    listener	
  
                                                   receives	
  
                                                   updates;	
  
                                                   min	
  +me	
  
                                                   and	
  min	
  
                                                   distance	
  
Reques+ng	
  User	
  Permissions	
  
•  You	
  must	
  add	
  permissions	
  in	
  order	
  to	
  get	
  user	
  
   loca+on	
  

	
  
	
  
•  ACCESS_COARSE_LOCATION	
  
    –  If	
  you	
  use	
  NETWORK_PROVIDER	
  
•  ACCESS_FINE_LOCATION	
  
    –  If	
  you	
  use	
  GPS_PROVIDER	
  or	
  NETWORK_PROVIDER	
  
Ge]ng	
  Last	
  Known	
  Loca+on	
  
•  First	
  loca+on	
  can	
  take	
  +me.	
  Use	
  cached	
  
   loca+on!	
  
    –  Loca+on	
  lastKnownLoca+on	
  =	
  
       loca+onManager.getLastKnownLoca+on(Loca+onManager
       .NETWORK_PROVIDER);	
  
Mock	
  Loca+on	
  Data	
  
•  If	
  you	
  don’t	
  have	
  Android	
  device,	
  you	
  can	
  use	
  
   emulator	
  for	
  loca+on	
  services	
  by	
  giving	
  mock	
  
   data	
  
•  Mock	
  data	
  works	
  only	
  with	
  GPS_PROVIDER	
  
•  Use	
  	
  
    –  Emulator	
  Control	
  View	
  from	
  Eclipse	
  
    –  DDMS	
  (Dalvik	
  Debug	
  Monitor	
  Server)	
  
    –  Geo	
  command	
  from	
  console	
  
Emulator	
  Control	
  View	
  
Geo	
  
•  Connect	
  to	
  emulator	
  from	
  console	
  
    –  telnet localhost <console-port>
•  Send	
  the	
  loca+on	
  data	
  
    –  geo fix -121 46
GOOGLE	
  MAPS	
  EXTERNAL	
  
DIRECTORY	
  
Google	
  Maps	
  
•  External	
  API	
  Add-­‐On	
  to	
  Android	
  SDK	
  
•  Install	
  Google	
  APIs	
  Add-­‐On	
  from	
  Android	
  SDK	
  
   and	
  AVD	
  Manager	
  (Google	
  APIs	
  by	
  Google)	
  
•  When	
  developing,	
  set	
  Google	
  API	
  Add-­‐On	
  as	
  
   target	
  
Google	
  APIs	
  as	
  Target	
  
Overview	
  
1.  Add	
  uses-­‐library	
  and	
  internet	
  permission	
  to	
  
    manifest	
  file	
  
2.  Use	
  the	
  Maps	
  API	
  
3.  Get	
  Maps	
  API	
  key	
  and	
  sign	
  your	
  app	
  
1.	
  Add	
  uses-­‐library	
  element	
  to	
  Manifest	
  file	
  

•  Because	
  we're	
  using	
  the	
  Google	
  Maps	
  library,	
  
   which	
  is	
  not	
  a	
  part	
  of	
  the	
  standard	
  Android	
  
   library,	
  we	
  need	
  to	
  declare	
  it	
  in	
  the	
  Android	
  
   Manifest	
  
    –  <uses-library
       android:name="com.google.android.maps" />
•  Internet	
  permissions	
  (downloadable	
  maps)	
  
    –  <uses-permission
         android:name="android.permission.INTERNET
         " />
    	
  
2.	
  Use	
  the	
  Maps	
  API:	
  MapView	
  
<?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="Your Maps API Key"
        />

</RelativeLayout>
2.	
  Use	
  the	
  Maps	
  API:	
  Class	
  
3.	
  Get	
  Maps	
  API	
  key	
  and	
  Sign	
  Your	
  App	
  
•  Create	
  MD5	
  cer+ficate	
  fingerprint	
  either	
  in	
  
   release	
  or	
  in	
  debug	
  
•  Release	
  
    –  $ keytool -list -alias alias_name -keystore
       my-release-key.keystore
•  Debug	
  
    –  $ keytool -list -alias androiddebugkey -
       keystore <path_to_debug_keystore>.keystore -
       storepass android -keypass android
•  Path	
  to	
  debug	
  keystore	
  in	
  Windows	
  Vista	
  
    –  C:Users<user>.androiddebug.keystore
3.	
  Sign	
  with	
  the	
  Service	
  
•  hQp://code.google.com/android/maps-­‐api-­‐
   signup.html	
  
Showing	
  La+tude	
  and	
  Longitude	
  on	
  Map	
  

	
  mapView	
  =	
  (MapView)	
  findViewById(R.id.mapview);	
  
	
  mapController	
  =	
  mapView.getController();	
  
	
  	
  	
  
	
  int	
  lat	
  =	
  (int)	
  (loca+on.getLa+tude()	
  *	
  1E6);	
  
	
  int	
  lng	
  =	
  (int)	
  (loca+on.getLongitude()	
  *	
  1E6);	
  
	
  	
  
	
  GeoPoint	
  point	
  =	
  new	
  GeoPoint(lat,	
  lng);	
  
	
  mapController.animateTo(point);	
  
             	
   	
  	
  
DISPLAYING	
  GRAPHICS	
  ON	
  MAPS	
  
Custom	
  Markers	
  
•  Overlay	
  –	
  Individual	
  item	
  on	
  map	
  
•  Create	
  custom	
  class	
  that	
  inherites	
  
   ItemizedOverlay	
  class	
  
•  ItemizedOverlay	
  class	
  is	
  a	
  base	
  class	
  for	
  an	
  
   Overlay	
  which	
  consists	
  of	
  a	
  list	
  of	
  
   OverlayItems.	
  
ItemizedOverlay	
  




          MyOverlayItems	
  

ArrayList<OverlayItem> items

void addOverLay(OverlayItem i)
OverlayItem createItem(int i)
int size()
…
Android Location and Maps
From	
  Ac+vity	
  
Android Location and Maps

More Related Content

PPTX
Android share preferences
PPTX
Android Layout.pptx
PPT
Google Maps in Android
PPTX
Notification android
PDF
Android resource
PDF
Action Bar in Android
PPT
Introduction to Eclipse IDE
Android share preferences
Android Layout.pptx
Google Maps in Android
Notification android
Android resource
Action Bar in Android
Introduction to Eclipse IDE

What's hot (20)

PPTX
Ii 1500-publishing your android application
PPTX
Android User Interface
PPTX
Android activity lifecycle
PPTX
Content provider in_android
PDF
Android Fragment
PDF
Android activity
PPTX
PPT
Java collections concept
PDF
Introduction to fragments in android
PPTX
Android UI
PDF
AndroidManifest
PDF
UI controls in Android
PDF
Android notification
PPTX
Android Intent.pptx
PDF
Android ui dialog
PPTX
android sqlite
PPSX
Introduction to .net framework
PDF
Android Telephony Manager and SMS
PPTX
SQLite database in android
PPT
Visual Studio IDE
Ii 1500-publishing your android application
Android User Interface
Android activity lifecycle
Content provider in_android
Android Fragment
Android activity
Java collections concept
Introduction to fragments in android
Android UI
AndroidManifest
UI controls in Android
Android notification
Android Intent.pptx
Android ui dialog
android sqlite
Introduction to .net framework
Android Telephony Manager and SMS
SQLite database in android
Visual Studio IDE
Ad

Viewers also liked (20)

PPT
Lecture Slides for Location based Services [Android]
PDF
Location-Based Services on Android
PDF
Android Security, Signing and Publishing
PDF
Android Essential Tools
PDF
Android Http Connection and SAX Parsing
PDF
Responsive Web Site Design
PDF
Quick Intro to Android Development
PDF
C# for Java Developers
PPTX
Qt Translations
PDF
Building Web Services
ODP
Google Maps API
PDF
Android ui menu
PDF
Android 2D Drawing and Animation Framework
PDF
Android Wi-Fi Manager and Bluetooth Connection
ODP
Android App Development - 06 Fragments
PDF
00 introduction-mobile-programming-course.ppt
PDF
Android UI Development
PDF
Android Threading
PDF
Android Data Persistence
PDF
Android Sensors
Lecture Slides for Location based Services [Android]
Location-Based Services on Android
Android Security, Signing and Publishing
Android Essential Tools
Android Http Connection and SAX Parsing
Responsive Web Site Design
Quick Intro to Android Development
C# for Java Developers
Qt Translations
Building Web Services
Google Maps API
Android ui menu
Android 2D Drawing and Animation Framework
Android Wi-Fi Manager and Bluetooth Connection
Android App Development - 06 Fragments
00 introduction-mobile-programming-course.ppt
Android UI Development
Android Threading
Android Data Persistence
Android Sensors
Ad

Similar to Android Location and Maps (20)

PDF
Android App Development 04 : Location API
PDF
International Journal of Engineering Research and Development
PDF
Mobile Application Development-Lecture 15 & 16.pdf
PDF
Android location
PDF
Developing Windows Phone Apps with Maps and Location Services
PDF
Core Location in iOS
PDF
Android GNSS in Nutshell
PPTX
gps_SEGMENTATION.pptx
PPTX
Android mobile application for gps
PDF
Matchinguu droidcon presentation
PPTX
U3-03-Google Location Based Services.pptx
PPTX
gps tracking techniques
PPT
Book Review Global Posiotining System
PPTX
FIWARE: Managing Context Information at large scale
ODP
Android App Development - 14 location, media and notifications
PPT
Synapseindia android apps development tutorial
PPT
Synapseindia android application development tutorial
PPTX
orioncontextbroker-20180615
PDF
THE DESIGN IN MOBILE AND WEB PLATFORM OF THE LOCATION IDENTIFICATION APPLICAT...
PPTX
Android application for gps
Android App Development 04 : Location API
International Journal of Engineering Research and Development
Mobile Application Development-Lecture 15 & 16.pdf
Android location
Developing Windows Phone Apps with Maps and Location Services
Core Location in iOS
Android GNSS in Nutshell
gps_SEGMENTATION.pptx
Android mobile application for gps
Matchinguu droidcon presentation
U3-03-Google Location Based Services.pptx
gps tracking techniques
Book Review Global Posiotining System
FIWARE: Managing Context Information at large scale
Android App Development - 14 location, media and notifications
Synapseindia android apps development tutorial
Synapseindia android application development tutorial
orioncontextbroker-20180615
THE DESIGN IN MOBILE AND WEB PLATFORM OF THE LOCATION IDENTIFICATION APPLICAT...
Android application for gps

More from Jussi Pohjolainen (20)

PDF
Moved to Speakerdeck
PDF
Java Web Services
PDF
Box2D and libGDX
PDF
libGDX: Screens, Fonts and Preferences
PDF
libGDX: Tiled Maps
PDF
libGDX: User Input and Frame by Frame Animation
PDF
Intro to Building Android Games using libGDX
PDF
Advanced JavaScript Development
PDF
Introduction to JavaScript
PDF
Introduction to AngularJS
PDF
libGDX: Scene2D
PDF
libGDX: Simple Frame Animation
PDF
libGDX: Simple Frame Animation
PDF
libGDX: User Input
PDF
Implementing a Simple Game using libGDX
PDF
Building Android games using LibGDX
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
PDF
Creating Games for Asha - platform
PDF
Intro to Asha UI
PDF
Intro to Java ME and Asha Platform
Moved to Speakerdeck
Java Web Services
Box2D and libGDX
libGDX: Screens, Fonts and Preferences
libGDX: Tiled Maps
libGDX: User Input and Frame by Frame Animation
Intro to Building Android Games using libGDX
Advanced JavaScript Development
Introduction to JavaScript
Introduction to AngularJS
libGDX: Scene2D
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
libGDX: User Input
Implementing a Simple Game using libGDX
Building Android games using LibGDX
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Games for Asha - platform
Intro to Asha UI
Intro to Java ME and Asha Platform

Recently uploaded (20)

PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Understanding_Digital_Forensics_Presentation.pptx

Android Location and Maps

  • 1. Android  Loca+on  and  Maps   Jussi  Pohjolainen  
  • 2. Loca+on  Services  and  Maps   •  Android  provides  loca+on  framework  that   your  app  can  use  to  determine     –  Device’s  loca+on   –  Listening  for  updates   •  Google  maps  external  library  available  for   displaying  and  managing  maps  
  • 4. Loca+on  Services   •  By  using  Loca+onManager  you  are  able  to   –  Query  for  the  list  of  Loca+onProviders  for  the  last   known  loca+on   –  Register  for  updates  of  the  user’s  current  loca+on   –  Register  for  given  Intent  to  be  fired  if  the  device   comes  within  given  proximity  of  given  lat/long  
  • 5. Obtaining  User  Loca+on   •  Loca+on  can  be  determined  via  GPS  and/or   cell  tower  +  Wi-­‐Fi  signals   •  GPS  is  accurate,  but  needs  outdoors,  fix  is   slower  and  it  uses  more  baQery.     •  To  request  loca+on,  you  use  Loca+onManager   -­‐  class    
  • 6. Reques+ng  Loca+on  Updates   Can  be  also   GPS_PROVIDER   Control   the   frequency   which   listener   receives   updates;   min  +me   and  min   distance  
  • 7. Reques+ng  User  Permissions   •  You  must  add  permissions  in  order  to  get  user   loca+on       •  ACCESS_COARSE_LOCATION   –  If  you  use  NETWORK_PROVIDER   •  ACCESS_FINE_LOCATION   –  If  you  use  GPS_PROVIDER  or  NETWORK_PROVIDER  
  • 8. Ge]ng  Last  Known  Loca+on   •  First  loca+on  can  take  +me.  Use  cached   loca+on!   –  Loca+on  lastKnownLoca+on  =   loca+onManager.getLastKnownLoca+on(Loca+onManager .NETWORK_PROVIDER);  
  • 9. Mock  Loca+on  Data   •  If  you  don’t  have  Android  device,  you  can  use   emulator  for  loca+on  services  by  giving  mock   data   •  Mock  data  works  only  with  GPS_PROVIDER   •  Use     –  Emulator  Control  View  from  Eclipse   –  DDMS  (Dalvik  Debug  Monitor  Server)   –  Geo  command  from  console  
  • 11. Geo   •  Connect  to  emulator  from  console   –  telnet localhost <console-port> •  Send  the  loca+on  data   –  geo fix -121 46
  • 12. GOOGLE  MAPS  EXTERNAL   DIRECTORY  
  • 13. Google  Maps   •  External  API  Add-­‐On  to  Android  SDK   •  Install  Google  APIs  Add-­‐On  from  Android  SDK   and  AVD  Manager  (Google  APIs  by  Google)   •  When  developing,  set  Google  API  Add-­‐On  as   target  
  • 14. Google  APIs  as  Target  
  • 15. Overview   1.  Add  uses-­‐library  and  internet  permission  to   manifest  file   2.  Use  the  Maps  API   3.  Get  Maps  API  key  and  sign  your  app  
  • 16. 1.  Add  uses-­‐library  element  to  Manifest  file   •  Because  we're  using  the  Google  Maps  library,   which  is  not  a  part  of  the  standard  Android   library,  we  need  to  declare  it  in  the  Android   Manifest   –  <uses-library android:name="com.google.android.maps" /> •  Internet  permissions  (downloadable  maps)   –  <uses-permission android:name="android.permission.INTERNET " />  
  • 17. 2.  Use  the  Maps  API:  MapView   <?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="Your Maps API Key"     /> </RelativeLayout>
  • 18. 2.  Use  the  Maps  API:  Class  
  • 19. 3.  Get  Maps  API  key  and  Sign  Your  App   •  Create  MD5  cer+ficate  fingerprint  either  in   release  or  in  debug   •  Release   –  $ keytool -list -alias alias_name -keystore my-release-key.keystore •  Debug   –  $ keytool -list -alias androiddebugkey - keystore <path_to_debug_keystore>.keystore - storepass android -keypass android •  Path  to  debug  keystore  in  Windows  Vista   –  C:Users<user>.androiddebug.keystore
  • 20. 3.  Sign  with  the  Service   •  hQp://code.google.com/android/maps-­‐api-­‐ signup.html  
  • 21. Showing  La+tude  and  Longitude  on  Map    mapView  =  (MapView)  findViewById(R.id.mapview);    mapController  =  mapView.getController();          int  lat  =  (int)  (loca+on.getLa+tude()  *  1E6);    int  lng  =  (int)  (loca+on.getLongitude()  *  1E6);        GeoPoint  point  =  new  GeoPoint(lat,  lng);    mapController.animateTo(point);        
  • 23. Custom  Markers   •  Overlay  –  Individual  item  on  map   •  Create  custom  class  that  inherites   ItemizedOverlay  class   •  ItemizedOverlay  class  is  a  base  class  for  an   Overlay  which  consists  of  a  list  of   OverlayItems.  
  • 24. ItemizedOverlay   MyOverlayItems   ArrayList<OverlayItem> items void addOverLay(OverlayItem i) OverlayItem createItem(int i) int size() …