Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Feb 19th, 2018 61 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. func calculateRoutes(from f: CLLocationCoordinate2D, to t: CLLocationCoordinate2D)  {
  2.  
  3.     let saddr = "(f.latitude),(f.longitude)"
  4.     let daddr = "(t.latitude),(t.longitude)"
  5.  
  6.     let url = "https://maps.googleapis.com/maps/api/directions/json?origin=(saddr)&destination=(daddr)&sensor=false&mode=driving&key=(googleApiKey)"
  7.  
  8.     Alamofire.request(url).responseJSON { response in
  9.  
  10.         do {
  11.             let json = try JSONSerialization.jsonObject(with: response.data!, options: .mutableContainers) as! NSDictionary
  12.  
  13.             let routes = (json.object(forKey: "routes") as! NSArray)
  14.  
  15.             if routes.count > 0 {
  16.  
  17.                 if let route = ((routes.object(at: 0) as? NSDictionary)?.object(forKey: "overview_polyline") as? NSDictionary)?.value(forKey: "points") as? String {
  18.  
  19.                     self.mapview.clear()
  20.  
  21.                     let path  = GMSPath(fromEncodedPath:route)!
  22.                     let polyline  = GMSPolyline(path: path)
  23.                     polyline.strokeColor = UIColor.black
  24.                     polyline.strokeWidth = 5.0
  25.                     polyline.map = self.mapview
  26.  
  27.                 }
  28.  
  29.             }
  30.  
  31.         } catch {
  32.         }
  33.  
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top