Android	  Loca+on	  and	  Maps	           Jussi	  Pohjolainen	  
Loca+on	  Services	  and	  Maps	  •  Android	  provides	  loca+on	  framework	  that	     your	  app	  can	  use	  to	  de...
LOCATION	  SERVICES	  
Loca+on	  Services	  •  By	  using	  Loca+onManager	  you	  are	  able	  to	     –  Query	  for	  the	  list	  of	  Loca+o...
Obtaining	  User	  Loca+on	  •  Loca+on	  can	  be	  determined	  via	  GPS	  and/or	       cell	  tower	  +	  Wi-­‐Fi	  s...
Reques+ng	  Loca+on	  Updates	                            Can	  be	  also	                           GPS_PROVIDER	        ...
Reques+ng	  User	  Permissions	  •  You	  must	  add	  permissions	  in	  order	  to	  get	  user	     loca+on	  	  	  •  ...
Ge]ng	  Last	  Known	  Loca+on	  •  First	  loca+on	  can	  take	  +me.	  Use	  cached	     loca+on!	      –  Loca+on	  la...
Mock	  Loca+on	  Data	  •  If	  you	  don’t	  have	  Android	  device,	  you	  can	  use	     emulator	  for	  loca+on	  s...
Emulator	  Control	  View	  
Geo	  •  Connect	  to	  emulator	  from	  console	      –  telnet localhost <console-port>•  Send	  the	  loca+on	  data	 ...
GOOGLE	  MAPS	  EXTERNAL	  DIRECTORY	  
Google	  Maps	  •  External	  API	  Add-­‐On	  to	  Android	  SDK	  •  Install	  Google	  APIs	  Add-­‐On	  from	  Android...
Google	  APIs	  as	  Target	  
Overview	  1.  Add	  uses-­‐library	  and	  internet	  permission	  to	      manifest	  file	  2.  Use	  the	  Maps	  API	 ...
1.	  Add	  uses-­‐library	  element	  to	  Manifest	  file	  •  Because	  were	  using	  the	  Google	  Maps	  library,	   ...
2.	  Use	  the	  Maps	  API:	  MapView	  <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schem...
2.	  Use	  the	  Maps	  API:	  Class	  
3.	  Get	  Maps	  API	  key	  and	  Sign	  Your	  App	  •  Create	  MD5	  cer+ficate	  fingerprint	  either	  in	     releas...
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);	  	  mapControlle...
DISPLAYING	  GRAPHICS	  ON	  MAPS	  
Custom	  Markers	  •  Overlay	  –	  Individual	  item	  on	  map	  •  Create	  custom	  class	  that	  inherites	     Item...
ItemizedOverlay	            MyOverlayItems	  ArrayList<OverlayItem> itemsvoid addOverLay(OverlayItem i)OverlayItem createI...
From	  Ac+vity	  
Android Location and Maps
Android Location and Maps
Upcoming SlideShare
Loading in …5
×

Android Location and Maps

2,255 views

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,255
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
109
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Android Location and Maps

  1. 1. Android  Loca+on  and  Maps   Jussi  Pohjolainen  
  2. 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  
  3. 3. LOCATION  SERVICES  
  4. 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. 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. 6. Reques+ng  Loca+on  Updates   Can  be  also   GPS_PROVIDER   Control   the   frequency   which   listener   receives   updates;   min  +me   and  min   distance  
  7. 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. 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. 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  
  10. 10. Emulator  Control  View  
  11. 11. Geo  •  Connect  to  emulator  from  console   –  telnet localhost <console-port>•  Send  the  loca+on  data   –  geo fix -121 46
  12. 12. GOOGLE  MAPS  EXTERNAL  DIRECTORY  
  13. 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. 14. Google  APIs  as  Target  
  15. 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. 16. 1.  Add  uses-­‐library  element  to  Manifest  file  •  Because  were  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. 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. 18. 2.  Use  the  Maps  API:  Class  
  19. 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. 20. 3.  Sign  with  the  Service  •  hQp://code.google.com/android/maps-­‐api-­‐ signup.html  
  21. 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);        
  22. 22. DISPLAYING  GRAPHICS  ON  MAPS  
  23. 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. 24. ItemizedOverlay   MyOverlayItems  ArrayList<OverlayItem> itemsvoid addOverLay(OverlayItem i)OverlayItem createItem(int i)int size()…
  25. 25. From  Ac+vity  

×