CH 3
CH 3
• ACCESS_COARSE_LOCATION
– If you use NETWORK_PROVIDER
• ACCESS_FINE_LOCATION
– If you use GPS_PROVIDER or NETWORK_PROVIDER
Getting Last Known Location
• First location can take time. Use cached
location!
– Location lastKnownLocation =
locationManager.getLastKnownLocation(LocationManager
.NETWORK_PROVIDER);
Mock Location Data
• If you don’t have Android device, you can use
emulator for location 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 location data
– geo fix -121 46
GOOGLE MAPS EXTERNAL DIRECTORY
Google Maps
• External API Add-O
‐ n 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
<com.google.android.maps.MapVie
w android:id="@+id/mapview"
android:layout_width="fill_pa
rent"
android:layout_height="fill_p
arent"
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 certificate 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>\.android\
debug.keystore
3. Sign with the Service
• http://code.google.com/android/maps-‐a‐pi-
signup.html
Showing Latitude and Longitude on Map
MyOverlayItems
ArrayList<OverlayItem> items
void
addOverLay(OverlayItem i)
OverlayItem
createItem(int i) int
size()
…
From Activity
Thank you