2017-10-20 66 views
0

你好,我只是想知道是否有任何方式返回一個地址的單位數與谷歌地方API。 (例如15號,123假法庭或#15號,123假法庭或15-123假法庭或15/123假法庭等)。以下是我嘗試使用的來自Google網站的示例代碼。我目前的代碼正在工作,它會返回一個地址,但我無法在其上添加任何單元/套件編號。謝謝您的幫助。從谷歌地方api返回的公寓號/單位號

import UIKit 
import GooglePlaces 

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: CGRect(x: 0, y: 65.0, width: 350.0, height: 45.0)) 

    subView.addSubview((searchController?.searchBar)!) 
    view.addSubview(subView) 
    searchController?.searchBar.sizeToFit() 
    searchController?.hidesNavigationBarDuringPresentation = false 

    // When UISearchController presents the results view, present it in 
    // this view controller, not one further up the chain. 
    definesPresentationContext = true 
    } 
} 

// Handle the user's selection. 
extension ViewController: GMSAutocompleteResultsViewControllerDelegate { 
    func resultsController(_ resultsController: GMSAutocompleteResultsViewController, 
         didAutocompleteWith place: GMSPlace) { 
    searchController?.isActive = false 
    // Do something with the selected place. 
    print("Place name: \(place.name)") 
    print("Place address: \(place.formattedAddress)") 
    print("Place attributions: \(place.attributions)") 
    } 

    func resultsController(_ resultsController: GMSAutocompleteResultsViewController, 
         didFailAutocompleteWithError error: Error){ 
    // TODO: handle the error. 
    print("Error: ", error.localizedDescription) 
    } 

    // Turn the network activity indicator on and off again. 
    func didRequestAutocompletePredictions(forResultsController resultsController: GMSAutocompleteResultsViewController) { 
    UIApplication.shared.isNetworkActivityIndicatorVisible = true 
    } 

    func didUpdateAutocompletePredictions(forResultsController resultsController: GMSAutocompleteResultsViewController) { 
    UIApplication.shared.isNetworkActivityIndicatorVisible = false 
    } 
} 
+0

我相信這是不可能的。 – Rhenz

回答

相關問題