Dispozitive Mobile de Calcul: Unit 12 - Localization Providers & Maps
Dispozitive Mobile de Calcul: Unit 12 - Localization Providers & Maps
MapFragment
Summary Showing current location
Displaying markers
Map controls
FETCH USER CURRENT LOCATION
Google API Client
USER LOCATION
• Location service: Context.LOCATION_SERVICE
– Used for creating a LocationManager object
• Location is determined using different sources such as:
– GPS receiver;
– WiFi networks;
– Mobile cell phone;
• Permissions
– android.permission.ACCESS_FINE_LOCATION
– android.permission.ACCESS_COARSE_LOCATION
USER LOCATION
• Google Play Service evaluation and Location Service
initialization;
• Initialization of a listener by specifying:
– The source used for getting the location;
– The amount of time between two different location queries;
• Notifications received when:
– location changes;
– the source providing data changes state;
USER LOCATION
Last known
location
Current
location
Location Updates
Method arguments:
• Google API client
• Location request
• Location listener
Stopping Location Updates
LocationManager class
@Override
/*position.getLatitude(), position.getLongitude(),
position.getAltitude(); */
}
LocationListener
• requestLocationUpdates() is used for getting the current location
• Parameters:
– The minimum time for querying updates
– The minimum distance for querying updates
• Other parameters:
– Location source:
• GPS_PROVIDER or NETWORK_PROVIDER (LocationManager)
• Selection criteria
– The LocationListener type object
• requestSingleUpdate()
Current position example
// create an object whose class implements LocationListener
LocListener locListener = new LocListener();
Latitude:
Google Inc. 37.422844
1600 Amphitheatre
Geocoding
Reverse (37°25'21.3"N)
Parkway Geocoding
Mountain View, CA 94043 Longitude:
Phone: +1 650-253-0000 -122.084342
(122°05'03.8"W)
Geocoder class
• Backend services
• Must check the availability of the service
– static method isPresent()
• Constructor initialization
– receives the Context of the application as single parameter
• INTERNET permission required
Methods
Address Lists
• getCountry()
• getCountryCode()
• getLocality()
• getAddressLine()
Getting addresses
GOOGLE MAPS
Google Maps
• Google Maps API v2
• Based on Google Maps service
• Included in Google Play services
– Found in the Extras category from SDK Manager
• Google Play services APK must be present on the mobile device
• Instruments:
– 3D maps, markers, paths, etc.
Google Maps
None
Hybrid Normal
Google
Maps
Satellite Terrain
Initialization
To get one, follow this link, follow the directions and press "Create" at the
end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backen
d&keyType=CLIENT_SIDE_ANDROID&r=E5:96:2C:F8:01:5F:04:99:62:81:3B:82:31:FC:6C:7F
:D1:B8:E4:6F%3Bcom.example.mihai.maps
You can also add your credentials to an existing key, using this line:
E5:96:2C:F8:01:5F:04:99:62:81:3B:82:31:FC:6C:7F:D1:B8:E4:6F;com.example.mihai.m
aps
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
Google Maps API v2
• com.google.android.gms.maps package
• MapView
– A control which encapsulates a map
• MapFragment
– The fragment object used for displaying the map
• UiSettings
– Control for setting the map preferences
Google Maps
• Map control
• Initialization
– MapFragment#getMap() or MapView#getMap()
• Camera control
– moveCamera(CameraUpdate)
– CameraUpdateFactory
• Map type
– setMapType(mapType const)
• MAP_TYPE_NORMAL, MAP_TYPE_SATELLITE, MAP_TYPE_TERRAIN
• Settings
• getUiSettings()
Google Maps
• Circle
– Circle addCircle(CircleOptions)
• Lines
– Polyline addPolyline(PolylineOptions)
• Images
– GroundOverlay addGroundOverlay(GroundOverlayOptions)
• Polygons
– Polygon addPolygon(PolygonOptions)
Google Maps API v2 classes
• Marker
– Small items on the map showing certain locations
– Properties
• Title
• Position (coordonate) – given as LatLng (latitude and longitude)
• Icon
• etc.
– GoogleMaps#addMarker(MarkerOptions)
• MarkerOptions
– Setting the Marker options
Google Maps
• Map fragment declared as an xml layout file (res/layout)
– fragment
• android:id="@+id/map"
• android:name="com.google.android.gms.maps.MapFragment"
• http://developer.android.com