質問編集履歴

2

誤字

2019/07/01 14:49

投稿

AppDvl
AppDvl

スコア58

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  #####聞きたいこと
2
2
 
3
- テーブルビューをmapの下に入れたくてストリートビューで”Memo”というビューにリンクさせた途端に”Thread 1: signal SIGABRT”のエラーになる、これの直し方
3
+ ストリートビューで”Memo”というビューにリンクさせた途端に”Thread 1: signal SIGABRT”のエラーになる、これの直し方
4
4
 
5
5
 
6
6
 
@@ -40,7 +40,7 @@
40
40
 
41
41
  ```ここに言語を入力
42
42
 
43
- //テーブルビューの設定/////////////////////////////////////////////////////////////////////////////////////////
43
+ //テーブルビューの設定////////////////////////////////////////////////////////////////////////////////////
44
44
 
45
45
  // ・行の数
46
46
 

1

コード追加

2019/07/01 14:48

投稿

AppDvl
AppDvl

スコア58

test CHANGED
File without changes
test CHANGED
@@ -76,12 +76,460 @@
76
76
 
77
77
 
78
78
 
79
-
80
-
81
-
82
-
83
79
  ![イメージ説明](a63e38f5a1685cef57bd99491ff84236.png)
84
80
 
85
81
  ![イメージ説明](5b9651141a997fd36a49d440e71299e8.png)
86
82
 
87
83
  ![イメージ説明](e083df8192126df90f656f32e72ce307.png)
84
+
85
+
86
+
87
+ #####コード全文
88
+
89
+
90
+
91
+ ```ここに言語を入力
92
+
93
+ //
94
+
95
+ // MemoViewController.swift
96
+
97
+ //
98
+
99
+
100
+
101
+ import UIKit
102
+
103
+ import MapKit
104
+
105
+ import CoreLocation
106
+
107
+
108
+
109
+ class MemoViewController:
110
+
111
+ UIViewController
112
+
113
+ ,UIImagePickerControllerDelegate
114
+
115
+ ,UINavigationControllerDelegate
116
+
117
+ ,CLLocationManagerDelegate
118
+
119
+ ,UITableViewDelegate{
120
+
121
+
122
+
123
+
124
+
125
+ @IBOutlet weak var mapTypeLabel: UILabel!
126
+
127
+ @IBOutlet weak var saveButton: UIBarButtonItem!
128
+
129
+ var locationManager:CLLocationManager!
130
+
131
+ var memo: String?//saveボタン用
132
+
133
+ @IBOutlet weak var memoTextField: UITextField!
134
+
135
+ @IBOutlet weak var map: MKMapView!
136
+
137
+ @IBOutlet weak var latiudeLabel: UILabel!
138
+
139
+ @IBOutlet weak var longitudeLabel: UILabel!
140
+
141
+ @IBOutlet weak var horizontalLabel: UILabel!
142
+
143
+ @IBOutlet weak var verticalLabel: UILabel!
144
+
145
+ @IBOutlet weak var measureButton: UIButton!
146
+
147
+ var coordinates = ["130.1111","33.1111","130.2222","33.2222"]
148
+
149
+ let width = UIScreen.main.bounds.size.width//画面の幅
150
+
151
+ let height = UIScreen.main.bounds.size.height//画面の高さ
152
+
153
+
154
+
155
+ var cnt : Int = 0 //表示領域を指定:はじめの1回だけ現在地をセンターにするためif cntを設置
156
+
157
+ @IBOutlet var coordinateCollection: [UICollectionView]!
158
+
159
+
160
+
161
+ @IBAction func measureButton(_ sender: Any) {
162
+
163
+ print("開始")
164
+
165
+ }
166
+
167
+ // 画面の切替
168
+
169
+ @objc func mapViewTypeBtnThouchDown(_ sender: Any) {
170
+
171
+ switch map.mapType {
172
+
173
+ case .satelliteFlyover: // 地図よりもデータを強調○
174
+
175
+ map.mapType = .standard
176
+
177
+ mapTypeLabel.text = "standard"
178
+
179
+ mapTypeLabel.frame = CGRect(x:10, y: 130, width:90, height:30)
180
+
181
+ print("standard")
182
+
183
+ break
184
+
185
+ case .standard: // 3D航空写真☓
186
+
187
+ map.mapType = .satelliteFlyover
188
+
189
+ mapTypeLabel.text = "3D"
190
+
191
+ mapTypeLabel.frame = CGRect(x:10, y: 130, width:33, height:30)
192
+
193
+ print("satelliteFlyover")
194
+
195
+ break
196
+
197
+
198
+
199
+ @unknown default:
200
+
201
+ break
202
+
203
+ }
204
+
205
+ }
206
+
207
+
208
+
209
+ override func viewDidLoad() {
210
+
211
+ super.viewDidLoad()
212
+
213
+ //テーブルビューの設定/////////////////////////////////
214
+
215
+ // ・行の数
216
+
217
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
218
+
219
+
220
+
221
+ return coordinates.count
222
+
223
+ }
224
+
225
+
226
+
227
+ // ・セルのスタイル、何を表示するか決める
228
+
229
+ func tableView(tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
230
+
231
+ let coordinatesCell = UITableViewCell(style: UITableViewCell.CellStyle.default , reuseIdentifier: "cds")
232
+
233
+ coordinatesCell.textLabel?.text = coordinates[indexPath.row]
234
+
235
+ return coordinatesCell
236
+
237
+ }
238
+
239
+
240
+
241
+
242
+
243
+ ////////////////////テーブルビューの設定//
244
+
245
+
246
+
247
+ horizontalLabel.frame = CGRect(x:10, y: 165, width:200, height:30)
248
+
249
+ verticalLabel.frame = CGRect(x:10, y: 165, width:200, height:30)
250
+
251
+ latiudeLabel.frame = CGRect(x:10, y: 165, width:200, height:30)
252
+
253
+ longitudeLabel.frame = CGRect(x:map.frame.origin.x + map.frame.size.width,
254
+
255
+ y: map.frame.origin.y + map.frame.size.height, width:300, height:30)
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+ locationManager = CLLocationManager()
266
+
267
+ locationManager.desiredAccuracy = kCLLocationAccuracyBest //最高精度
268
+
269
+
270
+
271
+ locationManager.requestAlwaysAuthorization()
272
+
273
+ locationManager.delegate = self // CLLocationManagerDelegat
274
+
275
+ locationManager.startUpdatingLocation()//観測開始
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+ self.navigationItem.title = "Edit Memo"
284
+
285
+ if let memo = self.memo{
286
+
287
+ self.memoTextField.text = memo
288
+
289
+ }
290
+
291
+ self.updateSaveButtonState()
292
+
293
+ // 地図の設定〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
294
+
295
+
296
+
297
+ map.mapType = MKMapType.satelliteFlyover
298
+
299
+ map.userTrackingMode = .follow
300
+
301
+ var mapViewType: UIButton!
302
+
303
+ mapViewType = UIButton(type: UIButton.ButtonType.detailDisclosure)
304
+
305
+ /////////////
306
+
307
+ mapViewType.frame = CGRect(x:10, y: 165, width:33, height:30)
308
+
309
+
310
+
311
+ mapViewType.layer.backgroundColor = UIColor(white: 1, alpha: 0.65).cgColor
312
+
313
+ mapViewType.layer.borderWidth = 0.5
314
+
315
+ mapViewType.layer.borderColor = UIColor.blue.cgColor
316
+
317
+ self.view.addSubview(mapViewType)
318
+
319
+
320
+
321
+
322
+
323
+ /////////////
324
+
325
+ mapTypeLabel.frame = CGRect(x:10, y: 130 , width:33, height:30)
326
+
327
+ mapTypeLabel.layer.backgroundColor = UIColor(white: 1, alpha: 0.8).cgColor
328
+
329
+ mapTypeLabel.layer.borderWidth = 0.5
330
+
331
+ mapTypeLabel.layer.borderColor = UIColor.blue.cgColor
332
+
333
+ self.view.addSubview(mapTypeLabel)
334
+
335
+ mapTypeLabel.text = "3D"
336
+
337
+ // 地図の表示タイプを切り替える関数
338
+
339
+ mapViewType.addTarget(self, action: #selector(mapViewTypeBtnThouchDown(_:)), for: .touchDown)
340
+
341
+
342
+
343
+ }
344
+
345
+ private func updateSaveButtonState(){
346
+
347
+ let memo = self.memoTextField.text ?? ""
348
+
349
+ self.saveButton.isEnabled = !memo.isEmpty
350
+
351
+ }
352
+
353
+ @IBAction func memoTextFieldChanged(_ sender: Any) {
354
+
355
+ updateSaveButtonState()
356
+
357
+ }
358
+
359
+
360
+
361
+ @IBAction func cancel(_ sender: Any) {
362
+
363
+
364
+
365
+ if self.presentingViewController is
366
+
367
+ UINavigationController {
368
+
369
+ self.dismiss(animated: true, completion: nil)
370
+
371
+ } else {
372
+
373
+ self.navigationController?.popViewController(animated: true)
374
+
375
+ }
376
+
377
+ }
378
+
379
+
380
+
381
+ override func didReceiveMemoryWarning() {
382
+
383
+ super.didReceiveMemoryWarning()
384
+
385
+ }
386
+
387
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
388
+
389
+ guard let button = sender as? UIBarButtonItem, button === self.saveButton else {
390
+
391
+ return
392
+
393
+ }
394
+
395
+ self.memo = self.memoTextField.text ?? ""
396
+
397
+ }
398
+
399
+ }
400
+
401
+
402
+
403
+ //位置情報の許可=============
404
+
405
+ extension MemoViewController {
406
+
407
+ func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
408
+
409
+ switch status {
410
+
411
+ case .notDetermined:
412
+
413
+ print("ユーザーはこのアプリケーションに関してまだ選択を行っていません")
414
+
415
+ locationManager.requestAlwaysAuthorization()
416
+
417
+ break
418
+
419
+ case .denied:
420
+
421
+ print("ローケーションサービスの設定が「無効」になっています (ユーザーによって、明示的に拒否されています)")
422
+
423
+
424
+
425
+ let alert : UIAlertController = UIAlertController(title: "測定を続けるには", message: "設定 > プライバシー > 位置情報サービス で、位置情報サービスの利用を許可して下さい。", preferredStyle: .alert)
426
+
427
+ let okAction = UIAlertAction(title:"OK", style: .default,handler: nil)
428
+
429
+ alert.addAction(okAction)
430
+
431
+ present(alert,animated: true,completion: nil)
432
+
433
+
434
+
435
+ break
436
+
437
+ case .restricted:
438
+
439
+ print("このアプリケーションは位置情報サービスを使用できません(ユーザによって拒否されたわけではありません)")
440
+
441
+
442
+
443
+ break
444
+
445
+ case .authorizedAlways:
446
+
447
+ print("常時、位置情報の取得が許可されています。")
448
+
449
+
450
+
451
+ break
452
+
453
+ case .authorizedWhenInUse:
454
+
455
+ print("起動時のみ、位置情報の取得が許可されています。")
456
+
457
+
458
+
459
+ locationManager.requestAlwaysAuthorization()
460
+
461
+ break
462
+
463
+ @unknown default:
464
+
465
+ break
466
+
467
+ }
468
+
469
+ }
470
+
471
+ //=====================位置情報の許可
472
+
473
+
474
+
475
+
476
+
477
+ func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {//GPSが更新すると呼ばれる
478
+
479
+ let location : CLLocation = locations[0]
480
+
481
+ let currentlocation = location.coordinate
482
+
483
+
484
+
485
+
486
+
487
+ if cnt == 0{
488
+
489
+ let reg : MKCoordinateRegion = MKCoordinateRegion(center: currentlocation,latitudinalMeters: 100,longitudinalMeters: 100)
490
+
491
+ map.region = reg
492
+
493
+
494
+
495
+ let viewPoint :CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude-0.005, location.coordinate.longitude)
496
+
497
+
498
+
499
+ map.showsBuildings = true
500
+
501
+
502
+
503
+ map.isPitchEnabled = true
504
+
505
+
506
+
507
+ let cameraVR : MKMapCamera = MKMapCamera(lookingAtCenter: currentlocation, fromEyeCoordinate: viewPoint, eyeAltitude: 100)
508
+
509
+ map.camera = cameraVR
510
+
511
+ cnt = 1
512
+
513
+ }
514
+
515
+
516
+
517
+ latiudeLabel.text = String("緯度:(location.coordinate.latitude)" )
518
+
519
+ longitudeLabel.text = String("経度:(location.coordinate.longitude)")
520
+
521
+ horizontalLabel.text = String("水平精度:(location.horizontalAccuracy)")
522
+
523
+ verticalLabel.text = String("垂直精度:(location.verticalAccuracy)")
524
+
525
+
526
+
527
+ }
528
+
529
+ }
530
+
531
+
532
+
533
+
534
+
535
+ ```