// AppDelegate.swiftimportUIKitimportGoogleMapsimportGooglePlaces@UIApplicationMainclassAppDelegate:UIResponder,UIApplicationDelegate{varwindow:UIWindow?funcapplication(_application:UIApplication,didFinishLaunchingWithOptionslaunchOptions:[UIApplicationLaunchOptionsKey:Any]?)->Bool{// Override point for customization after application launch.ifletpath=Bundle.main.path(forResource:"key",ofType:"plist"){ifletdic=NSDictionary(contentsOfFile:path)as?[String:Any]{ifletapiKey=dic["googleMapsApiKey"]as?String{GMSServices.provideAPIKey(apiKey)GMSPlacesClient.provideAPIKey(apiKey)}}}returntrue}...}
// ViewController.swiftimportUIKitimportGoogleMapsimportGooglePlacesclassViewController:UIViewController,GMSMapViewDelegate,CLLocationManagerDelegate{@IBOutletweakvarmapView:GMSMapView!privatevarlocationManager:CLLocationManager?privatevarcurrentLocation:CLLocation?privatevarplacesClient:GMSPlacesClient!privatevarzoomLevel:Float=15.0/// 初期描画の判断に利用privatevarinitView:Bool=falseoverridefuncviewDidLoad(){super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.// GoogleMapの初期化self.mapView.isMyLocationEnabled=trueself.mapView.mapType=GMSMapViewType.normalself.mapView.settings.compassButton=trueself.mapView.settings.myLocationButton=trueself.mapView.delegate=self// 位置情報関連の初期化self.locationManager=CLLocationManager()self.locationManager?.desiredAccuracy=kCLLocationAccuracyBestself.locationManager?.requestAlwaysAuthorization()self.locationManager?.distanceFilter=50self.locationManager?.startUpdatingLocation()self.locationManager?.delegate=selfself.placesClient=GMSPlacesClient.shared()}overridefuncdidReceiveMemoryWarning(){super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}// MARK: CLLocationManagerDelegatefunclocationManager(_manager:CLLocationManager,didUpdateLocationslocations:[CLLocation]){if!self.initView{// 初期描画時のマップ中心位置の移動letcamera=GMSCameraPosition.camera(withTarget:(locations.last?.coordinate)!,zoom:self.zoomLevel)self.mapView.camera=cameraself.locationManager?.stopUpdatingLocation()self.initView=true}}}