gpt4 book ai didi

ios - 在 IOS 上,寻找在 google place sdk 中检测当前位置的选项

转载 作者:行者123 更新时间:2023-11-29 11:44:18 26 4
gpt4 key购买 nike

我不熟悉 Swift3,但是我正在让自由职业者开发我的应用程序,但他们说,他们无法在我用 swift3 开发的 IOS 应用程序中添加检测当前位置的 google place api sdk 实现来搜索地址。我正在尝试实现如下所示的地址搜索页面

current location link should auto detect user's current location like on image

此功能中的任何指针都会有很大帮助。请分享我可以与开发人员分享以实现的此类实现的任何示例/教程。

最佳答案

首次安装

pod 'GooglePlaces'
pod 'GooglePlacePicker'
pod 'GoogleMaps'

然后按照下面的代码只是为了查看

import GoogleMaps
import GooglePlaces

class SrarchPlacesViewController: UIViewController, UISearchDisplayDelegate,UISearchBarDelegate {

@IBOutlet weak var searchView: UISearchBar!
var searchBar: UISearchBar?
var tableDataSource: GMSAutocompleteTableDataSource?
var srchDisplayController: UISearchDisplayController?
var resultsViewController: GMSAutocompleteResultsViewController?
var searchController: UISearchController?

override func viewDidLoad() {
super.viewDidLoad()
searchView.delegate = self
searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 250.0, height: 44.0))

tableDataSource = GMSAutocompleteTableDataSource()
tableDataSource?.delegate = self


srchDisplayController = UISearchDisplayController(searchBar: searchView, contentsController: self)
srchDisplayController?.searchResultsDataSource = tableDataSource
srchDisplayController?.searchResultsDelegate = tableDataSource

srchDisplayController?.delegate = self


}
@objc(didUpdateAutocompletePredictionsForTableDataSource:) func didUpdateAutocompletePredictions(for tableDataSource: GMSAutocompleteTableDataSource) {
// Turn the network activity indicator off.
UIApplication.shared.isNetworkActivityIndicatorVisible = false
// Reload table data.
srchDisplayController?.searchResultsTableView.reloadData()
}

@objc(didRequestAutocompletePredictionsForTableDataSource:) func didRequestAutocompletePredictions(for tableDataSource: GMSAutocompleteTableDataSource) {
// Turn the network activity indicator on.
UIApplication.shared.isNetworkActivityIndicatorVisible = true
// Reload table data.
srchDisplayController?.searchResultsTableView.reloadData()
}

//MARK:- SEARCH BAR FUCNTION

func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
// self.tableViews.hidden = true
dPrint("BIGIN")
}

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
// self.tableViews.hidden = false
dPrint("ending")

}

func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
// self.tableViews.hidden = false
dPrint("cancel")
}



func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if(searchText == ""){
dPrint("text chnange")
// self.tableViews.hidden = false
}

}

@objc(tableDataSource:didSelectPrediction:) func tableDataSource(_ tableDataSource: GMSAutocompleteTableDataSource, didSelect prediction: GMSAutocompletePrediction) -> Bool {
return true
}


}
extension SrarchPlacesViewController: GMSAutocompleteTableDataSourceDelegate{
/**
* Called when a non-retryable error occurred when retrieving autocomplete predictions or place
* details. A non-retryable error is defined as one that is unlikely to be fixed by immediately
* retrying the operation.
* <p>
* Only the following values of |GMSPlacesErrorCode| are retryable:
* <ul>
* <li>kGMSPlacesNetworkError
* <li>kGMSPlacesServerError
* <li>kGMSPlacesInternalError
* </ul>
* All other error codes are non-retryable.
* @param tableDataSource The |GMSAutocompleteTableDataSource| that generated the event.
* @param error The |NSError| that was returned.
*/
public func tableDataSource(_ tableDataSource: GMSAutocompleteTableDataSource, didFailAutocompleteWithError error: Error) {
dPrint("Error: \(error.localizedDescription)")
}

func tableDataSource(_ tableDataSource: GMSAutocompleteTableDataSource, didAutocompleteWith place: GMSPlace) {
srchDisplayController?.isActive = false

// Do something with the selected place.
print(place.coordinate)

print("Place name: \(place.name)")
print("Place address: \(place.formattedAddress)")
print("Place attributions: \(place.attributions)")
}

@objc(searchDisplayController:shouldReloadTableForSearchString:) func searchDisplayController(_ controller: UISearchDisplayController, shouldReloadTableForSearch searchString: String?) -> Bool {
tableDataSource?.sourceTextHasChanged(searchString)
return false
}


}

关于ios - 在 IOS 上,寻找在 google place sdk 中检测当前位置的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711207/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com