質問編集履歴
1
変更点のあったコードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,168 @@
|
|
1
|
+
swift 下の追記です
|
2
|
+
|
3
|
+
```
|
4
|
+
|
5
|
+
func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
|
6
|
+
|
7
|
+
{
|
8
|
+
|
9
|
+
UIApplication.shared.beginIgnoringInteractionEvents()
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
let activityIndicator = UIActivityIndicatorView()
|
14
|
+
|
15
|
+
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
|
16
|
+
|
17
|
+
activityIndicator.center = self.view.center
|
18
|
+
|
19
|
+
activityIndicator.hidesWhenStopped = true
|
20
|
+
|
21
|
+
activityIndicator.startAnimating()
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
self.view.addSubview(activityIndicator)
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
//Hide the search bar
|
30
|
+
|
31
|
+
searchBar.resignFirstResponder()
|
32
|
+
|
33
|
+
dismiss(animated: true, completion: nil)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
//Create the request
|
38
|
+
|
39
|
+
let searchRequest = MKLocalSearchRequest()
|
40
|
+
|
41
|
+
searchRequest.naturalLanguageQuery = searchBar.text
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
let activeSearch = MKLocalSearch(request: searchRequest)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
activeSearch.start{ (response, error) in
|
50
|
+
|
51
|
+
if response == nil
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
print("error")
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
else
|
60
|
+
|
61
|
+
{
|
62
|
+
|
63
|
+
//remove annotation
|
64
|
+
|
65
|
+
let annotations = self.mapView.annotations
|
66
|
+
|
67
|
+
self.mapView.removeAnnotation(annotations as! MKAnnotation)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
//getting date
|
72
|
+
|
73
|
+
let latitude = response?.boundingRegion.center.latitude
|
74
|
+
|
75
|
+
let longitude = response?.boundingRegion.center.longitude
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
//create annotation
|
80
|
+
|
81
|
+
let annotation = MKPointAnnotation()
|
82
|
+
|
83
|
+
annotation.title = searchBar.text
|
84
|
+
|
85
|
+
annotation.coordinate = CLLocationCoordinate2DMake(latitude!, longitude!)
|
86
|
+
|
87
|
+
self.mapView.addAnnotation(annotation)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
//zooming in on annotation
|
92
|
+
|
93
|
+
let coordinate:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude!, longitude!)
|
94
|
+
|
95
|
+
let span = MKCoordinateSpanMake(0.1, 0.1)
|
96
|
+
|
97
|
+
let region = MKCoordinateRegionMake(coordinate, span)
|
98
|
+
|
99
|
+
self.mapView.setRegion(region, animated: true)
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
func locationManager(_ manager: CLLocationManager, didUpdatelocations locations: [CLLocation])
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
print("成功")
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
let location = locations[0]
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
let span:MKCoordinateSpan = MKCoordinateSpanMake(location.coordinate.latitude, location.coordinate.longitude)
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
let myLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
|
128
|
+
|
129
|
+
mapView.setRegion(region, animated: true)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
self.mapView.showsUserLocation = true
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
override func viewDidLoad()
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
super.viewDidLoad()
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
mapView=MKMapView()
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
manager.delegate = self
|
154
|
+
|
155
|
+
manager.desiredAccuracy = kCLLocationAccuracyBest
|
156
|
+
|
157
|
+
manager.requestWhenInUseAuthorization()
|
158
|
+
|
159
|
+
manager.startUpdatingHeading()
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
}
|
164
|
+
|
1
|
-
### 前提・実現したいこと
|
165
|
+
```### 前提・実現したいこと
|
2
166
|
|
3
167
|
|
4
168
|
|