I am using google Place Autocomplete API, i need to add UITextField instead of UISearchBar with the same functionality. here is the working code with UISearchBar which i get from https://developers.google.com/places/ios-api/autocomplete. I will add textfield and tableview myself, if someone just help me to get array of addresses from any keyword of searching. like from string (of keyword) to array(predicted places).
import UIKit
import GoogleMaps
class ViewController: UIViewController {
var resultsViewController: GMSAutocompleteResultsViewController?
var searchController: UISearchController?
var resultView: UITextView?
override func viewDidLoad() {
super.viewDidLoad()
resultsViewController = GMSAutocompleteResultsViewController()
resultsViewController?.delegate = self
searchController = UISearchController(searchResultsController: resultsViewController)
searchController?.searchResultsUpdater = resultsViewController
let subView = UIView(frame: CGRectMake(0, 65.0, 350.0, 45.0))
subView.addSubview((searchController?.searchBar)!)
self.view.addSubview(subView)
searchController?.searchBar.sizeToFit()
searchController?.hidesNavigationBarDuringPresentation = false
self.definesPresentationContext = true
}
}
extension ViewController: GMSAutocompleteResultsViewControllerDelegate {
func resultsController(resultsController: GMSAutocompleteResultsViewController,
didAutocompleteWithPlace place: GMSPlace) {
searchController?.active = false
print("Place name: ", place.name)
print("Place address: ", place.formattedAddress!)
}
func resultsController(resultsController: GMSAutocompleteResultsViewController,
didFailAutocompleteWithError error: NSError){
print("Error: ", error.description)
}
func didRequestAutocompletePredictionsForResultsController(resultsController: GMSAutocompleteResultsViewController) {
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}
func didUpdateAutocompletePredictionsForResultsController(resultsController: GMSAutocompleteResultsViewController) {
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
}
For India Latitude and Longitude and this is a Right Answer A Jellies girl make this Downvote please check the code this is absolutely right answer
//In your View Controller there TextField and TableView Setup
// Also Setup App delegate
See The Output Image its work like this
By Govind Kumar 12-12-2017
If you're using a UITextField and your own UITableView in place of a UISearchController, then it's easier to use the GMSAutocompleteTableDataSource class directly.
One of the code samples for the GoogleMaps Cocoapod shows how to do this. Look for the file
SDKDemoAutocompleteWithTextFieldController
in thePods/GoogleMaps/GoogleMapsSDKDemos/SDKDemos/PlacesSamples
directory of your project if you've installed the pod, or runpod try GoogleMaps
to download the samples.Integrate your GPA(Google Places API). POD files are :
At first, provide your KEY to AppDelegate.swift
At first, take a text field and a table view. Then add these line to your ViewController.swift file and hook the textField and tableView and finally run it.