Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

Android Application Development

Google Maps API V2 Part 2


Google Maps API V2 The Map Object
The key class is the GoogleMap class.
GoogleMap handles the following
operations automatically:

1.Connecting to the Google Maps


service.
2. Downloading map tiles.
3. Displaying tiles on the device
screen.
4.Displaying various controls such as pan
and zoom.
5.Responding to pan and zoom
gestures by moving the map and
zooming in or out.
Add a Map to App
Google Maps API V2 Add a Fragment [1]
To define a Fragment object in an Activity's layout file, add a <fragment>
element. In this element, set the android:name attribute to"com.google.
android.gms.maps.MapFragment". This automatically attaches a
MapFragment to the Activity. [Part 1]
Add a Map to App
Google Maps API V2 Add a Fragment [3]
Getting GoogleMap object:
MapFragment activity_main.xml

With the handle to the GoogleMap object for the MapFragment, we can
set initial options for the map.
Add a Map to App
Google Maps API V2 Add a Fragment [3]
Verify Map Availability:
Before interacting with GoogleMap object, confirm map availability and
Google Play services components are correctly installed on the device.
Add a Map to App
Google Maps API V2 Map Types [1]
1.Normal: Typical road map. Roads, some man-made features, and important
natural features such as rivers are shown. Road and feature labels are also visible.
2.Hybrid: Satellite photograph data with road maps added. Road and feature labels
are also visible.
3. Satellite: Satellite photograph data. Road and feature labels are not visible.
4.Terrain: Topographic data. The map includes colors, contour lines and labels, and
perspective shading. Some roads and labels are also visible.
5.None: No tiles. The map will be rendered as an empty grid with no tiles
loaded.
Add a Map to App
Google Maps API V2 Map Types [2]

Normal Hybrid Terrain


Add a Map to App
Google Maps API V2 Set Properties in XML Attributes
LocationListner
• implements LocationListner
• Uses-Permission:
• android.permission.ACCESS_COARSE_LOCATION
• android.permission.ACCESS_FINE_LOCATION"
• Add unimplemented methods

• public void onLocationChanged(Location location)


• public void onProviderEnabled(String provider)
• public void onStatusChanged(String provider, int status, Bundle extras)
• public void onProviderDisabled(String arg0)

• LocationManager lm =getSystemService(LOCATION_SERVICE)

• ADD Criteria
• Accuracy/ ACCURACY_FINE , ACCURACY_COARSE /
• power usage/ POWER_HIGH , POWER_MEDIUM, POWER_LOW/
• LocationManager.requestLocationUpdates(provider, mills, distance,
LocationListner example

LocationManger locationManager=
(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

locationListener=new LocationListener(){
public void onLocationChanged( Location location){
LatLonPoint now=new LatLonPoint(loc.getLatitude(),loc.getLongitude());
}
public void onStatusChanged( String provider, int status, Bundle extras)
{
}
public void onProviderEnabled( String provider){
}
public void onProviderDisabled( String provider){
}
}; locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,0,0,locationListener);
GoogleMap[1]
Nested Classes(Interface)

• GoogleMap.OnCameraChangeListener

• GoogleMap.OnMapClickListener

• GoogleMap.OnMapLongClickListener

• GoogleMap.OnMarkerClickListener

• GoogleMap.OnMarkerDragListener
GoogleMap[2]
• animateCamera(CameraUpdate update)

• setMapType(int type)

• setMyLocationEnabled(boolean enabled)

• setOnCameraChangeListener(
GoogleMap.OnCameraChangeListener listener)

• setOnMapClickListener(GoogleMap.OnMapClickListener listener)

• setOnMarkerClickListener(GoogleMap.OnMarkerClickListener
listener)
GoogleMap[3]
• addCircle(CircleOptions options)

• addGroundOverlay(GroundOverlayOptions options)

• addMarker(MarkerOptions options)

• addPolygon(PolygonOptions options)

• addPolyline(PolylineOptions options)

You might also like