forked from truongminhthang/CodeSnippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC8694FD6-1E03-4F26-A2AF-D9D4568DED6E.codesnippet
69 lines (66 loc) · 2.86 KB
/
C8694FD6-1E03-4F26-A2AF-D9D4568DED6E.codesnippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>TopLevel</string>
</array>
<key>IDECodeSnippetContents</key>
<string>class DirectionServices: NSObject {
func queryDirection(source: CLLocationCoordinate2D, target: CLLocationCoordinate2D, callBack:@escaping(_ dict: Dictionary<String, AnyObject>) -> ()) {
let urlString = "https://maps.googleapis.com/maps/api/directions/json?origin=\(source.latitude),\(source.longitude)&destination=\(target.latitude),\(target.longitude)&key=\(AppConstant.googleMapkey)"
guard let url = URL(string: urlString) else {return }
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let task = session.dataTask(with: url) { (data, response, error) in
if let error = error {
print(error.localizedDescription)
} else if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
guard let aData = data else { print("Error: did not receive data"); return }
do {
guard let dict = try JSONSerialization.jsonObject(with: aData, options: []) as? Dictionary<String, AnyObject> else {
print("error trying to convert data to JSON")
return
}
callBack(dict)
} catch let error {
print(error)
}
}
}
}
task.resume()
}
}
class ImplementDrawPolylineClass: UIViewController {
func drawPolyline(json: Dictionary<String, AnyObject>) {
guard let routes = json["routes"] as? [Dictionary<String, AnyObject>] else {
return
}
guard let route = routes.first?["overview_polyline"] as? Dictionary<String, AnyObject> else {
return
}
guard let overview_route = route["points"] as? String else {
return
}
let path = GMSPath(fromEncodedPath: overview_route)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 8
polyline.strokeColor = UIColor.red
polyline.map = mapView
}
}</string>
<key>IDECodeSnippetIdentifier</key>
<string>C8694FD6-1E03-4F26-A2AF-D9D4568DED6E</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Swift</string>
<key>IDECodeSnippetTitle</key>
<string>Swift 3 - Google Map: Draw direction (polyline) from 2 place</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>