var GoogleURLAPI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=\(origin.latitude),\(origin.longitude)&radius=15000&type=Fast%20Food&keyword=Food&key=API KEY GoogleURLAPI = GoogleURLAPI.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! var urlRequest = URLRequest(url: URL(string: GoogleURLAPI)!) urlRequest.httpMethod = "GET" let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in if error == nil {//making sure it actually has something let jsonDict = try? JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary //setting jsonDict to read datta from url if let LocArray = jsonDict?.value(forKey: "results") as? NSArray { //print("or here",LocArray) for x in LocArray { if let Location = x as? NSDictionary { if let loc = Location.value(forKey: "location") { self.tester.append(loc as! String) //self.nameArray.append(loc as! String) } } } } self.printNames() //print("json = \(jsonDict)") } else { let alert = UIAlertController(title: "There was an Error", message: "We encountered an error while trying to connect to Google. Try again later.", preferredStyle: UIAlertController.Style.alert) alert.addAction(UIAlertAction(title: "Okay!", style: UIAlertAction.Style.default, handler: nil)) self.present(alert, animated: true, completion: nil) } } task.resume()