在iOS中使用GMSAutocompleteFetcherDelegate时如何查找经纬度

在iOS中使用GMSAutocompleteFetcherDelegate时如何查找经纬度,ios,swift,google-maps,Ios,Swift,Google Maps,根据Place Autocomplete文档,预测数组的对象没有位置信息。 那么我应该如何获得经度和纬度的详细信息呢。 以下是我的密码- extension ViewController: GMSAutocompleteFetcherDelegate { func didAutocomplete(with predictions: [GMSAutocompletePrediction]) { tableData.removeAll() for prediction in

根据Place Autocomplete文档,预测数组的对象没有位置信息。 那么我应该如何获得经度和纬度的详细信息呢。 以下是我的密码-

extension ViewController: GMSAutocompleteFetcherDelegate {


func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {

    tableData.removeAll()

    for prediction in predictions{

        tableData.append(prediction.attributedFullText.string)

    }
    locationTable.reloadData()
}

func didFailAutocompleteWithError(_ error: Error) {
    print(error.localizedDescription)
}

我建议您使用CoreLocation获取纬度和经度的位置:

import CoreLocation
class YourViewController 
{

let locationManager = CLLocationManager()
var locValue: CLLocationCoordinate2D! = nil


    override func viewDidLoad() {
    super.viewDidLoad()

    // Ask for Authorisation from the User.
    self.locationManager.requestAlwaysAuthorization()

    // For use in foreground
    self.locationManager.requestWhenInUseAuthorization()
    }


    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.startUpdatingLocation()
    }
}
这是代表

//MARK: - Location and alternative stuff

extension YourViewController : CLLocationManagerDelegate {

// MARK: Save actual position
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    self.locValue = locValue
    }
}

在表视图的
didSelectRowAtIndexPath
中使用以下方法。所以你会得到纬度,纬度和地址

我亲自使用过它,并测试了它的工作100%

根据您的swift版本,某些语法可能会发生变化

import GoogleMaps

func getLatLongFromAutocompletePrediction(prediction:GMSAutocompletePrediction){

    let placeClient = GMSPlacesClient()

    placeClient.lookUpPlaceID(prediction.placeID!) { (place, error) -> Void in
        if let error = error {
             //show error
            return
        }

        if let place = place {
            place.coordinate.longitude //longitude 
            place.coordinate.latitude //latitude
            obj.attributedFullText.string //Address in string
        } else {
            //show error
        }
    }
}

如果需要,请随时提问。

我不知道什么是
gmsautocomplefetcher
。你应该解释一下,或者在你的问题中添加相关的标签。请看我添加的以下答案。欢迎光临。