Android google mapv2

29
Android GoogleMap V2 資管系研 鍾聖彥 TA 指導師 余仁朋

description

 

Transcript of Android google mapv2

Page 1: Android google mapv2

Android GoogleMap V2

資管系研⼀一 鍾聖彥 TA 指導⽼老師 余仁朋 博⼠士

Page 2: Android google mapv2

Agenda

• Features • Showcase • How to begin

and develop? • Q&A

Page 3: Android google mapv2

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

Page 4: Android google mapv2

Showcases(1/3)

Page 5: Android google mapv2

Showcases(2/3)

Page 6: Android google mapv2

Showcases(3/3)

More…

Page 7: Android google mapv2

How to Begin and Develop?Answer is step by step.And learning example.

Page 8: Android google mapv2

Downloading Google Play ServicesOpen Eclipse ⇒ Windows ⇒ Android SDK Manager

Page 9: Android google mapv2

Importing Google Play Services into EclipseFile ⇒ Import ⇒ Android ⇒ Existing Android Code Into Workspace

Windows os :android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib

Page 10: Android google mapv2

Getting the Google Maps API keyWindow ⇒ 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

Page 11: Android google mapv2

Now open Google API Console If you have no Google Account…please hurry to registry

Page 12: Android google mapv2

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

Page 13: Android google mapv2

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

Page 14: Android google mapv2

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相同

Page 15: Android google mapv2

⾛走上這條路都是為了它...AIzaSyDacsY4MMgCfjc5A4IwLS6LQpz1ykIgzJk

Page 16: Android google mapv2

Creating New ProjectFile ⇒ New ⇒ Android Application Project

We need to copy Map API Key like this : AIzaSyDacsY4MMgCfjc5A4IwLS6LQpz1ykIgzJk

Page 17: Android google mapv2

Google Play Services project as a library to use project.

We need to copy Map API Key like this : AIzaSyDacsY4MMgCfjc5A4IwLS6LQpz1ykIgzJk

So right click on project and select properties.

Page 18: Android google mapv2

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.gms.version" android:value="@integer/google_play_services_version" />

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="API_KEY"/>

Page 19: Android google mapv2

Google maps needs following permissions and features.

ACCESS_NETWORK_STATE – To check network state whether data can be downloaded or notINTERNET – To check internet connection status WRITE_EXTERNAL_STORAGE – To write to external storage as google maps store map data in external storageACCESS_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

Page 20: Android google mapv2

GoogleMap Layout<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent" >

    <fragment

        android:id="@+id/map"

        android:name="com.google.android.gms.maps.MapFragment"

        android:layout_width="match_parent"

        android:layout_height="match_parent"/>

</RelativeLayout>

Page 21: Android google mapv2

Let’s Coding.

Page 22: Android google mapv2

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);

Page 23: Android google mapv2

Changing Marker Color// ROSE color icon marker.icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_ROSE));   // GREEN color icon marker.icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_GREEN)); !

Page 24: Android google mapv2

Changing Marker Color// ROSE color icon marker.icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_ROSE));   // GREEN color icon marker.icon(BitmapDescriptorFactory.defaultMarker( BitmapDescriptorFactory.HUE_GREEN)); !

Page 25: Android google mapv2

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);

Page 26: Android google mapv2

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));

Page 27: Android google mapv2

Changing Map TypegoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);

Page 28: Android google mapv2

Q&A

Page 29: Android google mapv2

https://developers.google.com/maps/documentation/android/ !

https://developers.google.com/maps/showcase/ !

http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/

!

http://blog.xuite.net/alenliu/test/66754055

Reference