質問編集履歴
1
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ContentView.swiftにGoogleMapを表示する方法がわからない
|
test
CHANGED
@@ -2,11 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
マップアプリとしてトップ画面にGoogleMapを表示すること
|
5
|
+
マップアプリとしてトップ画面にGoogleMapを表示することせん
|
6
|
-
|
7
|
-
このトップ画面にサイドメニューボタンと場所に情報を登録できるボタンを作りたいのですがどのファイルに記述すればいいのかわかりません
|
8
|
-
|
9
|
-
新しく作るのか
|
10
6
|
|
11
7
|
|
12
8
|
|
@@ -14,18 +10,128 @@
|
|
14
10
|
|
15
11
|
|
16
12
|
|
17
|
-
OMMMap(アプリ名)
|
13
|
+
NewOMMMap(アプリ名)
|
18
14
|
|
19
|
-
|
15
|
+
GoogleMapsView.swift
|
20
16
|
|
21
|
-
|
17
|
+
```Swift
|
22
18
|
|
23
|
-
|
19
|
+
import SwiftUI
|
24
20
|
|
25
|
-
|
21
|
+
import GoogleMaps
|
26
22
|
|
27
|
-
Assets.xcassets
|
28
23
|
|
29
|
-
LaunchScreen.storyboard
|
30
24
|
|
25
|
+
class GoogleMapsViewController: UIViewController, CLLocationManagerDelegate {
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
var locationManager = CLLocationManager()
|
30
|
+
|
31
|
+
lazy var mapView = GMSMapView()
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
override func viewDidLoad() {
|
36
|
+
|
37
|
+
super.viewDidLoad()
|
38
|
+
|
39
|
+
// Do any additional setup after loading the view.
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
//初期値はApple本社
|
44
|
+
|
45
|
+
let camera = GMSCameraPosition.camera(withLatitude: 37.3318, longitude: -122.0312, zoom: 17.0)
|
46
|
+
|
47
|
+
mapView = GMSMapView.map(withFrame: CGRect(origin: .zero, size: view.bounds.size), camera: camera)
|
48
|
+
|
49
|
+
mapView.settings.myLocationButton = true //右下のボタン追加する
|
50
|
+
|
51
|
+
mapView.isMyLocationEnabled = true
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
// User Location
|
56
|
+
|
57
|
+
locationManager.delegate = self
|
58
|
+
|
59
|
+
locationManager.requestWhenInUseAuthorization()
|
60
|
+
|
61
|
+
locationManager.desiredAccuracy = kCLLocationAccuracyBest
|
62
|
+
|
63
|
+
locationManager.startUpdatingLocation()
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
self.view.addSubview(mapView)
|
68
|
+
|
69
|
+
self.view.bringSubviewToFront(mapView)
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
//現在地が更新されたら呼び出される
|
76
|
+
|
77
|
+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
78
|
+
|
79
|
+
let userLocation = locations.last
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
let camera = GMSCameraPosition.camera(withLatitude: userLocation!.coordinate.latitude,
|
84
|
+
|
85
|
+
longitude: userLocation!.coordinate.latitude, zoom: 17.0)
|
86
|
+
|
87
|
+
self.mapView.animate(to: camera)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
locationManager.stopUpdatingLocation()
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
ContentView.swift
|
106
|
+
|
107
|
+
```Swift
|
108
|
+
|
31
|
-
|
109
|
+
import SwiftUI
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
struct ContentView: View {
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
var body: some View {
|
118
|
+
|
119
|
+
GoogleMapsView() #この記述で表示できると思っていたのですが、出来ない、、
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
struct ContentView_Previews: PreviewProvider {
|
128
|
+
|
129
|
+
static var previews: some View {
|
130
|
+
|
131
|
+
ContentView()
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
```
|