teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

修正

2020/07/24 02:32

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- ボタンをどこ作ればいいのかわからない
1
+ ContentView.swiftGoogleMapを表示する方法がわからない
body CHANGED
@@ -1,16 +1,69 @@
1
1
  現在マップアプリを作っています
2
2
 
3
- マップアプリとしてトップ画面にGoogleMapを表示することはできたのですが、
3
+ マップアプリとしてトップ画面にGoogleMapを表示することせん
4
- このトップ画面にサイドメニューボタンと場所に情報を登録できるボタンを作りたいのですがどのファイルに記述すればいいのかわかりません
5
- 新しく作るのか
6
4
 
7
5
  ファイル構造としては
8
6
 
9
- OMMMap(アプリ名)
7
+ NewOMMMap(アプリ名)
8
+ GoogleMapsView.swift
9
+ ```Swift
10
+ import SwiftUI
11
+ import GoogleMaps
12
+
13
+ class GoogleMapsViewController: UIViewController, CLLocationManagerDelegate {
14
+
15
+ var locationManager = CLLocationManager()
16
+ lazy var mapView = GMSMapView()
17
+
18
+ override func viewDidLoad() {
19
+ super.viewDidLoad()
20
+ // Do any additional setup after loading the view.
21
+
22
+ //初期値はApple本社
23
+ let camera = GMSCameraPosition.camera(withLatitude: 37.3318, longitude: -122.0312, zoom: 17.0)
24
+ mapView = GMSMapView.map(withFrame: CGRect(origin: .zero, size: view.bounds.size), camera: camera)
25
+ mapView.settings.myLocationButton = true //右下のボタン追加する
26
+ mapView.isMyLocationEnabled = true
27
+
28
+ // User Location
29
+ locationManager.delegate = self
30
+ locationManager.requestWhenInUseAuthorization()
31
+ locationManager.desiredAccuracy = kCLLocationAccuracyBest
32
+ locationManager.startUpdatingLocation()
33
+
34
+ self.view.addSubview(mapView)
35
+ self.view.bringSubviewToFront(mapView)
36
+ }
37
+
38
+ //現在地が更新されたら呼び出される
39
+ func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
40
+ let userLocation = locations.last
41
+
42
+ let camera = GMSCameraPosition.camera(withLatitude: userLocation!.coordinate.latitude,
43
+ longitude: userLocation!.coordinate.latitude, zoom: 17.0)
44
+ self.mapView.animate(to: camera)
45
+
46
+ locationManager.stopUpdatingLocation()
47
+ }
48
+
49
+ }
50
+
51
+ ```
52
+
10
- AppDelegate.swift
53
+ ContentView.swift
11
- SceneDelegate.swift
54
+ ```Swift
12
- ViewController.swift(ここにGoogleMap表示の記述をしました)
13
- Main.storyboard
14
- Assets.xcassets
15
- LaunchScreen.storyboard
16
- info.prist
55
+ import SwiftUI
56
+
57
+ struct ContentView: View {
58
+
59
+ var body: some View {
60
+ GoogleMapsView() #この記述で表示できると思っていたのですが、出来ない、、
61
+ }
62
+ }
63
+
64
+ struct ContentView_Previews: PreviewProvider {
65
+ static var previews: some View {
66
+ ContentView()
67
+ }
68
+ }
69
+ ```