質問編集履歴
1
変更点のあったコードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,88 @@
|
|
1
|
-
|
1
|
+
swift 下の追記です
|
2
|
+
```
|
3
|
+
func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
|
4
|
+
{
|
5
|
+
UIApplication.shared.beginIgnoringInteractionEvents()
|
2
6
|
|
7
|
+
let activityIndicator = UIActivityIndicatorView()
|
8
|
+
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
|
9
|
+
activityIndicator.center = self.view.center
|
10
|
+
activityIndicator.hidesWhenStopped = true
|
11
|
+
activityIndicator.startAnimating()
|
3
12
|
|
13
|
+
self.view.addSubview(activityIndicator)
|
14
|
+
|
15
|
+
//Hide the search bar
|
16
|
+
searchBar.resignFirstResponder()
|
17
|
+
dismiss(animated: true, completion: nil)
|
18
|
+
|
19
|
+
//Create the request
|
20
|
+
let searchRequest = MKLocalSearchRequest()
|
21
|
+
searchRequest.naturalLanguageQuery = searchBar.text
|
22
|
+
|
23
|
+
let activeSearch = MKLocalSearch(request: searchRequest)
|
24
|
+
|
25
|
+
activeSearch.start{ (response, error) in
|
26
|
+
if response == nil
|
27
|
+
{
|
28
|
+
print("error")
|
29
|
+
}
|
30
|
+
else
|
31
|
+
{
|
32
|
+
//remove annotation
|
33
|
+
let annotations = self.mapView.annotations
|
34
|
+
self.mapView.removeAnnotation(annotations as! MKAnnotation)
|
35
|
+
|
36
|
+
//getting date
|
37
|
+
let latitude = response?.boundingRegion.center.latitude
|
38
|
+
let longitude = response?.boundingRegion.center.longitude
|
39
|
+
|
40
|
+
//create annotation
|
41
|
+
let annotation = MKPointAnnotation()
|
42
|
+
annotation.title = searchBar.text
|
43
|
+
annotation.coordinate = CLLocationCoordinate2DMake(latitude!, longitude!)
|
44
|
+
self.mapView.addAnnotation(annotation)
|
45
|
+
|
46
|
+
//zooming in on annotation
|
47
|
+
let coordinate:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude!, longitude!)
|
48
|
+
let span = MKCoordinateSpanMake(0.1, 0.1)
|
49
|
+
let region = MKCoordinateRegionMake(coordinate, span)
|
50
|
+
self.mapView.setRegion(region, animated: true)
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
func locationManager(_ manager: CLLocationManager, didUpdatelocations locations: [CLLocation])
|
55
|
+
{
|
56
|
+
print("成功")
|
57
|
+
|
58
|
+
let location = locations[0]
|
59
|
+
|
60
|
+
let span:MKCoordinateSpan = MKCoordinateSpanMake(location.coordinate.latitude, location.coordinate.longitude)
|
61
|
+
|
62
|
+
let myLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
|
63
|
+
|
64
|
+
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
|
65
|
+
mapView.setRegion(region, animated: true)
|
66
|
+
|
67
|
+
self.mapView.showsUserLocation = true
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
override func viewDidLoad()
|
72
|
+
{
|
73
|
+
super.viewDidLoad()
|
74
|
+
|
75
|
+
mapView=MKMapView()
|
76
|
+
|
77
|
+
manager.delegate = self
|
78
|
+
manager.desiredAccuracy = kCLLocationAccuracyBest
|
79
|
+
manager.requestWhenInUseAuthorization()
|
80
|
+
manager.startUpdatingHeading()
|
81
|
+
|
82
|
+
}
|
83
|
+
```### 前提・実現したいこと
|
84
|
+
|
85
|
+
|
4
86
|
ユーザーの現在位置をマップ上に表示したい
|
5
87
|
### 発生している問題・エラーメッセージ
|
6
88
|
|