google maps sdk for ios 1.4

32
Google Map SDK for iOS Michael Pan 13812星期

Upload: michael-pan

Post on 10-May-2015

808 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Google maps SDK for iOS 1.4

Google Map SDK for iOSMichael Pan

13年8月12⽇日星期⼀一

Page 2: Google maps SDK for iOS 1.4

Official Web Pagehttp://bit.ly/12j2w8r

13年8月12⽇日星期⼀一

Page 3: Google maps SDK for iOS 1.4

We want to build

13年8月12⽇日星期⼀一

Page 4: Google maps SDK for iOS 1.4

Get Google Map API Key• 從 Google APIs Console 產⽣生 API 專案.

13年8月12⽇日星期⼀一

Page 5: Google maps SDK for iOS 1.4

Google API Console - My Project

13年8月12⽇日星期⼀一

Page 6: Google maps SDK for iOS 1.4

Services

13年8月12⽇日星期⼀一

Page 7: Google maps SDK for iOS 1.4

Create new iOS Key

13年8月12⽇日星期⼀一

Page 8: Google maps SDK for iOS 1.4

Configure Project • Input bundle ID

13年8月12⽇日星期⼀一

Page 9: Google maps SDK for iOS 1.4

API Console Updated

13年8月12⽇日星期⼀一

Page 10: Google maps SDK for iOS 1.4

Download SDK• https://dl.google.com/geosdk/GoogleMaps-iOS-1.4.0.zip

• Version 1.4.0 (July 2013)

13年8月12⽇日星期⼀一

Page 11: Google maps SDK for iOS 1.4

Drag Framework into Project 1.4

13年8月12⽇日星期⼀一

Page 12: Google maps SDK for iOS 1.4

Drag Framework into Project 1.4

13年8月12⽇日星期⼀一

Page 13: Google maps SDK for iOS 1.4

Drag GoogleMaps.bundle 1.4

13年8月12⽇日星期⼀一

Page 14: Google maps SDK for iOS 1.4

Drag GoogleMaps.bundle 1.4

13年8月12⽇日星期⼀一

Page 15: Google maps SDK for iOS 1.4

Google Maps SDK Framework

13年8月12⽇日星期⼀一

Page 16: Google maps SDK for iOS 1.4

Configure Xcode Project - Library

原本就有, 其他請⼿手動加⼊入

1.1

13年8月12⽇日星期⼀一

Page 17: Google maps SDK for iOS 1.4

Configure Xcode Project - Library

原本就有, 其他請⼿手動加⼊入

1.4

13年8月12⽇日星期⼀一

Page 18: Google maps SDK for iOS 1.4

Setting

13年8月12⽇日星期⼀一

Page 19: Google maps SDK for iOS 1.4

Create Single View Application

UIView

13年8月12⽇日星期⼀一

Page 20: Google maps SDK for iOS 1.4

Some code with Key• AppDelegate.m

#import "AppDelegate.h"#import <GoogleMaps/GoogleMaps.h>@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [GMSServices provideAPIKey:@"key-Nk64"]; return YES;}

13年8月12⽇日星期⼀一

Page 21: Google maps SDK for iOS 1.4

Change Class

@interface ViewController ()@property (weak, nonatomic) IBOutlet GMSMapView *gmapView;

@end

13年8月12⽇日星期⼀一

Page 22: Google maps SDK for iOS 1.4

Run it

13年8月12⽇日星期⼀一

Page 23: Google maps SDK for iOS 1.4

User Location - View Controller- (void)viewDidLoad{ [super viewDidLoad]; self.gMapView.myLocationEnabled = YES; self.gMapView.settings.myLocationButton = YES;}

13年8月12⽇日星期⼀一

Page 24: Google maps SDK for iOS 1.4

Run

13年8月12⽇日星期⼀一

Page 25: Google maps SDK for iOS 1.4

Zoom Action- (IBAction)moveToLocation:(id)sender { CLLocationCoordinate2D userLocation = self.gMapView.myLocation.coordinate; self.gMapView.camera =[GMSCameraPosition cameraWithLatitude:userLocation.latitude longitude:userLocation.longitude zoom:20]; }

1.4

13年8月12⽇日星期⼀一

Page 26: Google maps SDK for iOS 1.4

Add mark- (IBAction)addMark:(id)sender {

CLLocationCoordinate2D userLocation = self.gMapView.myLocation.coordinate; GMSMarker *school = [[GMSMarker alloc] init]; school.position = CLLocationCoordinate2DMake(userLocation.latitude+0.001, userLocation.longitude+0.001); school.snippet = @"School"; school.map = self.gMapView;

GMSMarker *hostpital = [[GMSMarker alloc] init]; hostpital.position = CLLocationCoordinate2DMake(userLocation.latitude-0.001, userLocation.longitude-0.001); hostpital.snippet = @"Hospital"; hostpital.map = self.gMapView;}

13年8月12⽇日星期⼀一

Page 27: Google maps SDK for iOS 1.4

Add markers

13年8月12⽇日星期⼀一

Page 28: Google maps SDK for iOS 1.4

Street View• GMSPanoramaView

• GMSPanoramaViewDelegate

13年8月12⽇日星期⼀一

Page 29: Google maps SDK for iOS 1.4

StreetViewController.m-(void) loadView{ [super loadView]; self.view = [GMSPanoramaView panoramaWithFrame:CGRectZero nearCoordinate:self.nearCoordinate]; [(GMSPanoramaView *)self.view setDelegate:self];}

- (void)panoramaView:(GMSPanoramaView *)panoramaView didMoveCamera:(GMSPanoramaCamera *)camera { NSLog(@"Camera: (%f,%f,%f)", camera.orientation.heading, camera.orientation.pitch, camera.zoom);}

13年8月12⽇日星期⼀一

Page 30: Google maps SDK for iOS 1.4

Tap info window of Marker

-(void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker{ NSLog(@"%@", marker.snippet); StreetViewController * streetViewController = [StreetViewController new]; streetViewController.nearCoordinate = CLLocationCoordinate2DMake(40.761388, -73.978133); [self presentViewController:streetViewController animated:YES completion:^{ ; }];}

self.gMapView.delegate = self;

13年8月12⽇日星期⼀一

Page 31: Google maps SDK for iOS 1.4

Run

13年8月12⽇日星期⼀一

Page 32: Google maps SDK for iOS 1.4

Traffic Info- (IBAction)showTraffic:(UISwitch *)sender { self.gMapView.trafficEnabled = sender.on;}

13年8月12⽇日星期⼀一