3. Google Map V2 Features
•
3D Rendering
•
Draw on the Map
•
•
•
•
•
Customize markers and info windows,
or add polylines and polygons.
Vector Tiles
Faster Loading with fewer demands on
bandwidth.
Gesture Control
Intuitive tilt, rotate and zoom gesture
controls.
•
Indoor Floor Plans
•
Location Services
3
9. Importing Google Play Services into Eclipse
File
Import
Android
Existing Android Code Into Workspace
Windows os :android-sdk-windowsextrasgooglegoogle_play_serviceslibprojectgoogle-play-services_lib
10. Getting the Google Maps API key
Window
Preferences
Android
Build
We need to copy SHA1 fingerprint like this : C1:C8:C4:5F:15:82:BC:85:E2:5B:CA:F2:6F:C3:EF:02:01:A1:F2:F4
11. Now open
Google API Console
If you have no Google Account…please hurry to registry
12. Enabled Google Maps Android API v2
We need to copy SHA1 fingerprint like this : C1:C8:C4:5F:15:82:BC:85:E2:5B:CA:F2:6F:C3:EF:02:01:A1:F2:F4
13. New Project
We need to copy SHA1 fingerprint like this : C1:C8:C4:5F:15:82:BC:85:E2:5B:CA:F2:6F:C3:EF:02:01:A1:F2:F4
14. Registered apps
We need to copy SHA1 fingerprint like this : C1:C8:C4:5F:15:82:BC:85:E2:5B:CA:F2:6F:C3:EF:02:01:A1:F2:F4
Package Name要與專案package相同
17. Google Play Services project as a library to use project.
So right click on project and select properties.
We need to copy Map API Key like this : AIzaSyDacsY4MMgCfjc5A4IwLS6LQpz1ykIgzJk
18. Add the Map Key in the manifest file.
We need to copy Map API Key like this : AIzaSyDacsY4MMgCfjc5A4IwLS6LQpz1ykIgzJk
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
19. Google maps needs following permissions and features.
ACCESS_NETWORK_STATE
– To check network state whether data can be downloaded or not
INTERNET
– To check internet connection status
WRITE_EXTERNAL_STORAGE
– To write to external storage as google maps store map data in external storage
ACCESS_COARSE_LOCATION
– To determine user’s location using WiFi and mobile cell data
ACCESS_FINE_LOCATION
– To determine user’s location using GPS
OpenGL ES V2
– Required for Google Maps V2
22. Placing a Marker
// latitude and longitude
double latitude = ;
double longitude = ;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps ");
// adding marker
googleMap.addMarker(marker);
23. Changing Marker Color
// ROSE color icon
marker.icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_ROSE));
// GREEN color icon
marker.icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_GREEN));
!
24. Changing Marker Color
// ROSE color icon
marker.icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_ROSE));
// GREEN color icon
marker.icon(BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_GREEN));
!
25. Custom Marker Icon
// latitude and longitude
double latitude = 17.385044;
double longitude = 78.486671;
// create marker
MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude,
longitude)).title("Hello Maps");
// Changing marker icon
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon)));
// adding marker
googleMap.addMarker(marker);
26. Moving Camera to a Location with
animation
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(17.385044, 78.486671)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition
(cameraPosition));