Sie sind auf Seite 1von 27

Androld Locauon and Maps

!ussl oh[olalnen
Locauon Servlces and Maps
Androld provldes locauon framework LhaL
your app can use Lo deLermlne
uevlce's locauon
LlsLenlng for updaLes
!""#$% '()* !"#!$%&' ')*$&$+ avallable for
dlsplaylng and managlng maps
+,-./0,1 23450-32
Locauon Servlces
8y uslng LocauonManager you are able Lo
Cuery for Lhe llsL of Locauonrovlders for Lhe lasL
known locauon
8eglsLer for updaLes of Lhe user's currenL locauon
8eglsLer for glven lnLenL Lo be red lf Lhe devlce
comes wlLhln glven proxlmlLy of glven laL/long
CbLalnlng user Locauon
Locauon can be deLermlned vla CS and/or
cell Lower + Wl-ll slgnals
CS ls accuraLe, buL needs ouLdoors, x ls
slower and lL uses more bauery.
1o requesL locauon, you use LocauonManager
- class

8equesung Locauon updaLes
Can be also
CS_8CvluL8
ConLrol
Lhe
frequency
whlch
llsLener
recelves
updaLes,
mln ume
and mln
dlsLance
8equesung user ermlsslons
?ou musL add permlsslons ln order Lo geL user
locauon


ACCLSS_CCA8SL_LCCA1lCn
lf you use nL1WC8k_8CvluL8
ACCLSS_llnL_LCCA1lCn
lf you use CS_8CvluL8 or nL1WC8k_8CvluL8
Cemng LasL known Locauon
llrsL locauon can Lake ume. use cached
locauon!
Locauon lasLknownLocauon =
locauonManager.geLLasLknownLocauon(LocauonManager
.nL1WC8k_8CvluL8),
Mock Locauon uaLa
lf you don'L have Androld devlce, you can use
emulaLor for locauon servlces by glvlng mock
daLa
Mock daLa 6"78* "9$: 6;<= !>2?>4,50@34
use
LmulaLor ConLrol vlew from Lcllpse
uuMS (ualvlk uebug MonlLor Server)
Ceo command from console
LmulaLor ConLrol vlew
Ceo
ConnecL Lo emulaLor from console
telnet localhost <console-port>
Send Lhe locauon daLa
geo fix -121 46
!,,!+3 A.>2 3B/341.+
@043-/,4C
Coogle Maps
3D<%79($ .>0 .EEF,9 Lo Androld Suk
lnsLall Coogle Als Add-Cn from Androld Suk
and Avu Manager (Coogle Als by Coogle)
When developlng, seL Coogle Al Add-Cn as
LargeL
Coogle Als as 1argeL
Cvervlew
1. Add uses-llbrary and lnLerneL permlsslon Lo
manlfesL le
2. use Lhe Maps Al
3. CeL Maps Al key and slgn your app
1. Add uses-llbrary elemenL Lo ManlfesL le
8ecause we're uslng Lhe Coogle Maps llbrary,
whlch ls noL a parL of Lhe sLandard Androld
llbrary, we need Lo declare lL ln Lhe Androld
ManlfesL
<uses-library
android:name="com.google.android.maps" />
lnLerneL permlsslons (downloadable maps)
<uses-permission
android:name="android.permission.INTERNET
" />

2. use Lhe Maps Al: Mapvlew
<?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 Lhe Maps Al: Class
3. CeL Maps Al key and Slgn ?our App
CreaLe Mu3 cerucaLe ngerprlnL elLher ln
release or ln debug
8elease
$ keytool -list -alias alias_name -keystore
my-release-key.keystore
uebug
$ keytool -list -alias androiddebugkey -
keystore <path_to_debug_keystore>.keystore -
storepass android -keypass android
aLh Lo debug keysLore ln Wlndows vlsLa
C:\Users\<user>\.android\debug.keystore
3. Slgn wlLh Lhe Servlce
hup://code.google.com/androld/maps-apl-
slgnup.hLml
Showlng LauLude and LonglLude on Map
mapvlew = (Mapvlew) ndvlew8yld(8.ld.mapvlew),
mapConLroller = mapvlew.geLConLroller(),

lnL laL = (lnL) (locauon.geLLauLude() * 1L6),
lnL lng = (lnL) (locauon.geLLonglLude() * 1L6),

CeoolnL polnL = new CeoolnL(laL, lng),
mapConLroller.anlmaLe1o(polnL),

@02>+.C01! !4.>G0-2 ,1 A.>2
CusLom Markers
Overlay , -%.)/).0&' )#!1 2% 1&3
CreaLe cusLom class LhaL lnherlLes
ItemizedOverlay class
ItemizedOverlay class ls a base class for an
Cverlay whlch conslsLs of a llsL of
CverlaylLems.
MyCverlaylLems
lLemlzedCverlay
ArrayList<OverlayItem> items

void addOverLay(OverlayItem i)
OverlayItem createItem(int i)
int size()


lrom AcuvlLy

Das könnte Ihnen auch gefallen