質問編集履歴
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -52,17 +52,17 @@
|
|
52
52
|
let camera = GMSCameraPosition.camera(withLatitude: userLocation!.coordinate.latitude,
|
53
53
|
longitude: userLocation!.coordinate.latitude, zoom: 15.0)
|
54
54
|
self.mapView.animate(to: camera)
|
55
|
-
|
56
|
-
locationManager.stopUpdatingLocation()
|
57
55
|
|
58
56
|
//マーカー追加
|
59
57
|
let marker = GMSMarker()
|
60
|
-
longitude = locations.coordinate.longitude //エラー Value of type '[CLLocation]' has no member 'coordinate'
|
61
|
-
latitude = locations.coordinate.latitude //エラー Value of type '[CLLocation]' has no member 'coordinate'
|
62
|
-
|
63
|
-
marker.position =
|
58
|
+
marker.position = CLLocationCoordinate2D(latitude: userLocation!.coordinate.latitude,
|
59
|
+
longitude: userLocation!.coordinate.latitude)
|
64
60
|
marker.title = "Hello World"
|
65
61
|
marker.map = mapView
|
62
|
+
|
63
|
+
locationManager.stopUpdatingLocation()
|
64
|
+
|
65
|
+
|
66
66
|
}
|
67
67
|
|
68
68
|
@IBAction func goBack(_ sender: Any) {
|
@@ -71,4 +71,5 @@
|
|
71
71
|
|
72
72
|
}
|
73
73
|
|
74
|
+
|
74
75
|
```
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,42 +1,47 @@
|
|
1
|
+
開発環境
|
2
|
+
Xcode 11.6
|
3
|
+
Swift 5.2.4
|
4
|
+
|
1
5
|
現在マップアプリを作っているものです
|
2
6
|
|
3
|
-
[
|
7
|
+
[Swiftで現在地を取得してみた](https://qiita.com/ftsan/items/b3a04d30cd91c11aeea1)を見ながら現在地を取得してそこにマーカーをたてようとしています
|
4
|
-
Googleマップに現在地を表示すること、マーカーをたてるところまでやりました
|
5
8
|
|
6
|
-
|
9
|
+
マーカーの場所の初期値を決めればマーカーをたてれるのですが、マーカーの位置を現在地を取得してそこにたてるということが出来ません
|
7
10
|
|
8
|
-
|
11
|
+
現在のコード
|
9
12
|
```Swift
|
10
13
|
import UIKit
|
11
14
|
import GoogleMaps
|
12
15
|
|
13
|
-
class
|
16
|
+
class SecondViewController: UIViewController, CLLocationManagerDelegate {
|
14
17
|
|
15
18
|
var locationManager = CLLocationManager()
|
16
19
|
lazy var mapView = GMSMapView()
|
20
|
+
var longitude: CLLocationDegrees!
|
21
|
+
var latitude: CLLocationDegrees!
|
22
|
+
|
17
23
|
|
18
24
|
override func viewDidLoad() {
|
19
25
|
super.viewDidLoad()
|
20
|
-
// Do any additional setup after loading the view.
|
21
26
|
|
22
27
|
//初期値は立川駅
|
23
|
-
// マップに指定の緯度経度の場所を指定の倍率で表示するように指示
|
24
28
|
let camera = GMSCameraPosition.camera(withLatitude: 35.6978368, longitude: 139.4137252, zoom: 15.0)
|
25
|
-
// GMSMapViewインスタンスを生成
|
26
29
|
mapView = GMSMapView.map(withFrame: CGRect(origin: .zero, size: view.bounds.size), camera: camera)
|
30
|
+
//右下のボタン追加する
|
27
|
-
mapView.settings.myLocationButton = true
|
31
|
+
mapView.settings.myLocationButton = true
|
28
32
|
mapView.isMyLocationEnabled = true
|
29
|
-
|
33
|
+
|
30
34
|
// User Location
|
31
35
|
locationManager.delegate = self
|
32
36
|
locationManager.requestWhenInUseAuthorization()
|
33
37
|
locationManager.desiredAccuracy = kCLLocationAccuracyBest
|
34
|
-
//
|
38
|
+
//位置情報取得を開始
|
35
39
|
locationManager.startUpdatingLocation()
|
36
40
|
|
37
41
|
self.view.addSubview(mapView)
|
38
42
|
self.view.insertSubview(mapView, at:0)
|
39
43
|
|
44
|
+
|
40
45
|
}
|
41
46
|
|
42
47
|
|
@@ -49,32 +54,21 @@
|
|
49
54
|
self.mapView.animate(to: camera)
|
50
55
|
|
51
56
|
locationManager.stopUpdatingLocation()
|
57
|
+
|
58
|
+
//マーカー追加
|
59
|
+
let marker = GMSMarker()
|
60
|
+
longitude = locations.coordinate.longitude //エラー Value of type '[CLLocation]' has no member 'coordinate'
|
61
|
+
latitude = locations.coordinate.latitude //エラー Value of type '[CLLocation]' has no member 'coordinate'
|
62
|
+
|
63
|
+
marker.position = //ここにlongitude(経度)とlatitude(緯度)をで現在地を読み込もうとしている
|
64
|
+
marker.title = "Hello World"
|
65
|
+
marker.map = mapView
|
52
66
|
}
|
53
67
|
|
68
|
+
@IBAction func goBack(_ sender: Any) {
|
69
|
+
dismiss(animated: true, completion: nil)
|
70
|
+
}
|
71
|
+
|
54
72
|
}
|
55
73
|
|
56
|
-
|
57
|
-
```
|
58
|
-
|
59
|
-
追記
|
60
|
-
|
61
|
-
[こちらの記事](https://qiita.com/powerispower/items/39203e1e908149fead19)の目標座標にピンをたてる、の
|
62
|
-
|
63
|
-
marker.positionの部分を現在地にすれば良いのかなと思いました
|
64
|
-
|
65
|
-
```Swift
|
66
|
-
override func loadView() {
|
67
|
-
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 10.0)
|
68
|
-
|
69
|
-
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
|
70
|
-
view = mapView
|
71
|
-
|
72
|
-
// 追加箇所
|
73
|
-
// markerはピンの場所
|
74
|
-
let marker = GMSMarker()
|
75
|
-
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
|
76
|
-
marker.title = "Sydney"
|
77
|
-
marker.snippet = "Australia"
|
78
|
-
marker.map = mapView
|
79
|
-
}
|
80
74
|
```
|
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,4 +76,5 @@
|
|
76
76
|
marker.title = "Sydney"
|
77
77
|
marker.snippet = "Australia"
|
78
78
|
marker.map = mapView
|
79
|
+
}
|
79
|
-
|
80
|
+
```
|
1
追記
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
GoogleMap SDK for IOSを使って現在地にマーカーを
|
1
|
+
GoogleMap SDK for IOSを使って現在地にマーカーをたてたい
|
body
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
現在マップアプリを作っているものです
|
2
2
|
|
3
3
|
[公式サイト](https://developers.google.com/maps/documentation)とQiitaを見ながら
|
4
|
-
Googleマップに現在地を表示すること、マーカーを
|
4
|
+
Googleマップに現在地を表示すること、マーカーをたてるところまでやりました
|
5
5
|
|
6
|
-
次に現在地を取得してそこにマーカーを
|
6
|
+
次に現在地を取得してそこにマーカーをたてるということをしたいのですが、どうやれば良いでしょうか
|
7
7
|
|
8
8
|
ViewConroller.swift
|
9
9
|
```Swift
|
@@ -54,4 +54,26 @@
|
|
54
54
|
}
|
55
55
|
|
56
56
|
|
57
|
-
```
|
57
|
+
```
|
58
|
+
|
59
|
+
追記
|
60
|
+
|
61
|
+
[こちらの記事](https://qiita.com/powerispower/items/39203e1e908149fead19)の目標座標にピンをたてる、の
|
62
|
+
|
63
|
+
marker.positionの部分を現在地にすれば良いのかなと思いました
|
64
|
+
|
65
|
+
```Swift
|
66
|
+
override func loadView() {
|
67
|
+
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 10.0)
|
68
|
+
|
69
|
+
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
|
70
|
+
view = mapView
|
71
|
+
|
72
|
+
// 追加箇所
|
73
|
+
// markerはピンの場所
|
74
|
+
let marker = GMSMarker()
|
75
|
+
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
|
76
|
+
marker.title = "Sydney"
|
77
|
+
marker.snippet = "Australia"
|
78
|
+
marker.map = mapView
|
79
|
+
}```
|