質問編集履歴

2

2017/11/13 07:39

投稿

madotuki
madotuki

スコア8

test CHANGED
File without changes
test CHANGED
@@ -170,71 +170,179 @@
170
170
 
171
171
  @IBAction func changedMapType(_ sender: UISegmentedControl) {
172
172
 
173
+ switch sender.selectedSegmentIndex {
174
+
175
+ case 0 :
176
+
177
+ // 地図
178
+
179
+ myMap.mapType = .standard
180
+
181
+ // 俯角(見下ろす角度)
182
+
183
+ myMap.camera.pitch = 0.0
184
+
185
+ // ツールバーを標準に戻す
186
+
187
+ toolBar.tintColor = defaultColor
188
+
189
+ toolBar.alpha = 1.0
190
+
191
+ case 1 :
192
+
193
+ // 衛星写真
194
+
195
+ myMap.mapType = .satellite
196
+
197
+ // ツールバーを黒文字、背景半透明にする
198
+
199
+ toolBar.tintColor = UIColor.black
200
+
201
+ toolBar.alpha = 0.8
202
+
203
+ case 2 :
204
+
205
+ // 写真+地図(ハイブリッド)
206
+
207
+ myMap.mapType = .hybrid
208
+
209
+ // ツールバーを黒文字、背景半透明にする
210
+
211
+ toolBar.tintColor = UIColor.black
212
+
213
+ toolBar.alpha = 0.8
214
+
215
+ case 3:
216
+
217
+ // 地図
218
+
219
+ myMap.mapType = .standard
220
+
221
+ // ツールバーを標準に戻す
222
+
223
+ toolBar.tintColor = defaultColor
224
+
225
+ toolBar.alpha = 1.0
226
+
227
+ // 3Dビュー
228
+
229
+ myMap.camera.pitch = 70 // 俯角(見下ろす角度)
230
+
231
+ myMap.camera.altitude = 700 // 標高
232
+
233
+ default:
234
+
235
+ break
236
+
237
+ }
238
+
239
+ }
240
+
241
+
242
+
243
+ // トラッキングモードを切り替える
244
+
245
+ @IBAction func tapTrackingButton(_ sender: UIBarButtonItem) {
246
+
173
247
  getRoute()
174
248
 
175
- switch sender.selectedSegmentIndex {
176
-
177
- case 0 :
178
-
179
- // 地図
180
-
181
- myMap.mapType = .standard
182
-
183
- // 俯角(見下ろ角度)
184
-
185
- myMap.camera.pitch = 0.0
186
-
187
- // ツールバーを標準に戻す
188
-
189
- toolBar.tintColor = defaultColor
190
-
191
- toolBar.alpha = 1.0
192
-
193
- case 1 :
194
-
195
- // 衛星写真
196
-
197
- myMap.mapType = .satellite
198
-
199
- // ツールバーを黒文字、背景半透明にする
200
-
201
- toolBar.tintColor = UIColor.black
202
-
203
- toolBar.alpha = 0.8
204
-
205
- case 2 :
206
-
207
- // 写真+地図(ハイブリッド)
208
-
209
- myMap.mapType = .hybrid
210
-
211
- // ツールバーを黒文字、背景半透明にする
212
-
213
- toolBar.tintColor = UIColor.black
214
-
215
- toolBar.alpha = 0.8
216
-
217
- case 3:
218
-
219
- // 地図
220
-
221
- myMap.mapType = .standard
222
-
223
- // ツールバーを標準に戻す
224
-
225
- toolBar.tintColor = defaultColor
226
-
227
- toolBar.alpha = 1.0
228
-
229
- // 3Dビュー
230
-
231
- myMap.camera.pitch = 70 // 俯角(見下ろす角度)
232
-
233
- myMap.camera.altitude = 700 // 標高
249
+ switch myMap.userTrackingMode {
250
+
251
+ case .none:
252
+
253
+ // noneからfollowへ
254
+
255
+ myMap.setUserTrackingMode(.follow, animated: true)
256
+
257
+ // トラッキングボタンを変更
258
+
259
+ trackingButton.image = UIImage(named: "trackingFollow")
260
+
261
+ case .follow:
262
+
263
+ // followからfollowWithHeadingへ
264
+
265
+ myMap.setUserTrackingMode(.followWithHeading, animated: true)
266
+
267
+ // トラッキングボタンを変更する
268
+
269
+ trackingButton.image = UIImage(named: "trackingHeading")
270
+
271
+ case .followWithHeading:
272
+
273
+ // followWithHeadingからnoneへ
274
+
275
+ myMap.setUserTrackingMode(.none, animated: true)
276
+
277
+ // トラッキングボタンを変更する
278
+
279
+ trackingButton.image = UIImage(named: "trackingNone")
280
+
281
+ }
282
+
283
+ }
284
+
285
+
286
+
287
+ // トラッキングが自動解除された
288
+
289
+ func mapView(_ mapView: MKMapView, didChange mode: MKUserTrackingMode, animated: Bool) {
290
+
291
+ // トラッキングボタンを変更する
292
+
293
+ trackingButton.image = UIImage(named: "trackingNone")
294
+
295
+ }
296
+
297
+
298
+
299
+ // 位置情報利用許可のステータスが変わった
300
+
301
+ func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
302
+
303
+
304
+
305
+ userLocation = CLLocationCoordinate2DMake(manager.location!.coordinate.latitude, manager.location!.coordinate.longitude)
306
+
307
+
308
+
309
+ // 現在地の取得を開始
310
+
311
+ self.locationManager.startUpdatingLocation()
312
+
313
+
314
+
315
+
316
+
317
+ switch status {
318
+
319
+ case .authorizedAlways, .authorizedWhenInUse :
320
+
321
+ // ロケーションの更新を開始
322
+
323
+ locationManager.startUpdatingLocation()
324
+
325
+ // トラッキングボタンを有効
326
+
327
+ trackingButton.isEnabled = true
234
328
 
235
329
  default:
236
330
 
331
+ // ロケーションの更新を停止
332
+
333
+ locationManager.stopUpdatingLocation()
334
+
335
+ // トラッキングモードをnoneに
336
+
337
+ myMap.setUserTrackingMode(.none, animated: true)
338
+
339
+ //トラッキングボタンを変更
340
+
341
+ trackingButton.image = UIImage(named: "trackingNone")
342
+
343
+ // トラッキングボタンを無効にする
344
+
237
- break
345
+ trackingButton.isEnabled = false
238
346
 
239
347
  }
240
348
 
@@ -242,242 +350,134 @@
242
350
 
243
351
 
244
352
 
245
- // トラッキングモードを切り替える
246
-
247
- @IBAction func tapTrackingButton(_ sender: UIBarButtonItem) {
248
-
249
- switch myMap.userTrackingMode {
250
-
251
- case .none:
252
-
253
- // noneからfollowへ
254
-
255
- myMap.setUserTrackingMode(.follow, animated: true)
256
-
257
- // トラッキングボタンを変更する
258
-
259
- trackingButton.image = UIImage(named: "trackingFollow")
260
-
261
- case .follow:
262
-
263
- // followからfollowWithHeadingへ
264
-
265
- myMap.setUserTrackingMode(.followWithHeading, animated: true)
266
-
267
- // トラッキングボタンを変更する
268
-
269
- trackingButton.image = UIImage(named: "trackingHeading")
270
-
271
- case .followWithHeading:
272
-
273
- // followWithHeadingからnoneへ
274
-
275
- myMap.setUserTrackingMode(.none, animated: true)
276
-
277
- // トラッキングボタンを変更する
278
-
279
- trackingButton.image = UIImage(named: "trackingNone")
353
+
354
+
355
+
356
+
357
+
358
+
359
+ override func viewDidLoad() {
360
+
361
+ super.viewDidLoad()
362
+
363
+ // スケールを表示する
364
+
365
+ myMap.showsScale = true
366
+
367
+
368
+
369
+ locationManager.requestWhenInUseAuthorization()
370
+
371
+
372
+
373
+ locationManager.delegate = self
374
+
375
+
376
+
377
+ myMap.delegate = self
378
+
379
+
380
+
381
+
382
+
383
+ }
384
+
385
+
386
+
387
+ override func didReceiveMemoryWarning() {
388
+
389
+ super.didReceiveMemoryWarning()
390
+
391
+ // Dispose of any resources that can be recreated.
392
+
393
+ }
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+ func getRoute()
402
+
403
+ {
404
+
405
+ // 現在地と目的地のMKPlacemarkを生成
406
+
407
+ var fromPlacemark = MKPlacemark(coordinate:userLocation, addressDictionary:nil)
408
+
409
+ var toPlacemark = MKPlacemark(coordinate:destLocation, addressDictionary:nil)
410
+
411
+
412
+
413
+ // MKPlacemark から MKMapItem を生成
414
+
415
+ var fromItem = MKMapItem(placemark:fromPlacemark)
416
+
417
+ var toItem = MKMapItem(placemark:toPlacemark)
418
+
419
+
420
+
421
+ // MKMapItem をセットして MKDirectionsRequest を生成
422
+
423
+ let myRequest: MKDirectionsRequest = MKDirectionsRequest()
424
+
425
+
426
+
427
+
428
+
429
+ myRequest.source = fromItem
430
+
431
+ myRequest.destination = toItem
432
+
433
+ myRequest.requestsAlternateRoutes = true
434
+
435
+ myRequest.transportType = MKDirectionsTransportType.any
436
+
437
+
438
+
439
+ let directions = MKDirections(request:myRequest)
440
+
441
+ directions.calculate(completionHandler: {
442
+
443
+ (response:MKDirectionsResponse!, error:NSError!) -> Void in
444
+
445
+
446
+
447
+ _ = response.routes.count
448
+
449
+ if (error != nil || response.routes.isEmpty) {
450
+
451
+ return
452
+
453
+ }
454
+
455
+ var route: MKRoute = response.routes[0] as MKRoute
456
+
457
+ // 経路を描画
458
+
459
+ self.myMap.add(route.polyline)
460
+
461
+ } as! MKDirectionsHandler)
462
+
463
+
464
+
465
+ func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
466
+
467
+ let route: MKPolyline = overlay as! MKPolyline
468
+
469
+ let routeRenderer = MKPolylineRenderer(polyline:route)
470
+
471
+ routeRenderer.lineWidth = 5.0
472
+
473
+ routeRenderer.strokeColor = UIColor.red
474
+
475
+ return routeRenderer
280
476
 
281
477
  }
282
478
 
283
479
  }
284
480
 
285
-
286
-
287
- // トラッキングが自動解除された
288
-
289
- func mapView(_ mapView: MKMapView, didChange mode: MKUserTrackingMode, animated: Bool) {
290
-
291
- // トラッキングボタンを変更する
292
-
293
- trackingButton.image = UIImage(named: "trackingNone")
294
-
295
- }
296
-
297
-
298
-
299
- // 位置情報利用許可のステータスが変わった
300
-
301
- func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
302
-
303
-
304
-
305
- userLocation = CLLocationCoordinate2DMake(manager.location!.coordinate.latitude, manager.location!.coordinate.longitude)
306
-
307
-
308
-
309
- // 現在地の取得を開始
310
-
311
- self.locationManager.startUpdatingLocation()
312
-
313
-
314
-
315
-
316
-
317
- switch status {
318
-
319
- case .authorizedAlways, .authorizedWhenInUse :
320
-
321
- // ロケーションの更新を開始
322
-
323
- locationManager.startUpdatingLocation()
324
-
325
- // トラッキングボタンを有効
326
-
327
- trackingButton.isEnabled = true
328
-
329
- default:
330
-
331
- // ロケーションの更新を停止
332
-
333
- locationManager.stopUpdatingLocation()
334
-
335
- // トラッキングモードをnoneに
336
-
337
- myMap.setUserTrackingMode(.none, animated: true)
338
-
339
- //トラッキングボタンを変更
340
-
341
- trackingButton.image = UIImage(named: "trackingNone")
342
-
343
- // トラッキングボタンを無効にする
344
-
345
- trackingButton.isEnabled = false
346
-
347
- }
348
-
349
- }
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
- override func viewDidLoad() {
360
-
361
- super.viewDidLoad()
362
-
363
- // スケールを表示する
364
-
365
- myMap.showsScale = true
366
-
367
-
368
-
369
- locationManager.requestWhenInUseAuthorization()
370
-
371
-
372
-
373
- locationManager.delegate = self
374
-
375
-
376
-
377
- myMap.delegate = self
378
-
379
-
380
-
381
-
382
-
383
- }
384
-
385
-
386
-
387
- override func didReceiveMemoryWarning() {
388
-
389
- super.didReceiveMemoryWarning()
390
-
391
- // Dispose of any resources that can be recreated.
392
-
393
- }
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
- func getRoute()
402
-
403
- {
404
-
405
- // 現在地と目的地のMKPlacemarkを生成
406
-
407
- var fromPlacemark = MKPlacemark(coordinate:userLocation, addressDictionary:nil)
408
-
409
- var toPlacemark = MKPlacemark(coordinate:destLocation, addressDictionary:nil)
410
-
411
-
412
-
413
- // MKPlacemark から MKMapItem を生成
414
-
415
- var fromItem = MKMapItem(placemark:fromPlacemark)
416
-
417
- var toItem = MKMapItem(placemark:toPlacemark)
418
-
419
-
420
-
421
- // MKMapItem をセットして MKDirectionsRequest を生成
422
-
423
- let myRequest: MKDirectionsRequest = MKDirectionsRequest()
424
-
425
-
426
-
427
-
428
-
429
- myRequest.source = fromItem
430
-
431
- myRequest.destination = toItem
432
-
433
- myRequest.requestsAlternateRoutes = true
434
-
435
- myRequest.transportType = MKDirectionsTransportType.any
436
-
437
-
438
-
439
- let directions = MKDirections(request:myRequest)
440
-
441
- directions.calculate(completionHandler: {
442
-
443
- (response:MKDirectionsResponse!, error:NSError!) -> Void in
444
-
445
-
446
-
447
- _ = response.routes.count
448
-
449
- if (error != nil || response.routes.isEmpty) {
450
-
451
- return
452
-
453
- }
454
-
455
- var route: MKRoute = response.routes[0] as MKRoute
456
-
457
- // 経路を描画
458
-
459
- self.myMap.add(route.polyline)
460
-
461
- } as! MKDirectionsHandler)
462
-
463
-
464
-
465
- func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
466
-
467
- let route: MKPolyline = overlay as! MKPolyline
468
-
469
- let routeRenderer = MKPolylineRenderer(polyline:route)
470
-
471
- routeRenderer.lineWidth = 5.0
472
-
473
- routeRenderer.strokeColor = UIColor.red
474
-
475
- return routeRenderer
476
-
477
- }
478
-
479
- }
480
-
481
481
  }
482
482
 
483
483
 

1

誤字の訂正

2017/11/13 07:39

投稿

madotuki
madotuki

スコア8

test CHANGED
File without changes
test CHANGED
@@ -132,7 +132,7 @@
132
132
 
133
133
  // 目的地
134
134
 
135
- var destLocation = CLLocationCoordinate2D(latitude: 35.644111, longitude: 139.747222)
135
+ var destLocation = CLLocationCoordinate2D(latitude: 35.658611, longitude: 139.745556)
136
136
 
137
137
 
138
138