如何在表格视图中获取Google Places中的选定位置坐标自动完成预测iOS Swift

时间:2018-09-09 15:26:52

标签: ios swift google-places-api

我可以使用以下代码在表格视图中获取Google Places自动完成结果。 现在我在寻找如何获取选定的Tableview坐标?

 func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
    tableData.removeAll()

    for predicition in predictions
    {
         tableData.append(predicition.attributedFullText.string)
    }
    table1.reloadData()
}

如果我选择表格视图的行,则下面的方法将被调用,我想获取该特定位置的坐标

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

}

1 个答案:

答案 0 :(得分:0)

从GMSAutocompletePrediction中,您将获得library(lubridate) library(dplyr) library(lme4) set.seed(1) # define the number of subjects in each groups n_g3 = 20 n_g2 = n_g3 * 10 n_g1 = n_g3 * 10 # 3 different groups id_p1 = paste0("ID",1:c(n_g1 + n_g2 + n_g3)) id_p2 = paste0("ID",c(n_g1+1):c(n_g1 + n_g2 + n_g3)) id_p3 = paste0("ID",c(n_g1 + n_g2+1):c(n_g1 + n_g2 + n_g3)) id = append(append(id_p1, id_p2), id_p3) # 3 different groups groups = c(rep("g1", n_g1), rep("g2", n_g2), rep("g3", n_g3), rep("g2", n_g2), rep("g3", n_g3), rep("g3", n_g3)) # 1st, 2nd or 3rd procedure procedure = c(rep("p1", n_g1), rep("p1", n_g2), rep("p1", n_g3), rep("p2", n_g2), rep("p2", n_g3), rep("p3", n_g3)) # measurement n??2 dichotomous y1 = c(rep(1, n_g1 + n_g2 + n_g3), (rbinom(c(n_g2 + n_g3),1,0.8)), (rbinom(n_g3,1,0.3)) ) data = data.frame(id, groups, procedure, y1) ### create subset g2 of data to make comparisons within the group with 2 procedures data_g2 = data[which(data$groups == "g2"),] table(data_g2$y1[data_g2$procedure == "p1"]) table(data_g2$y1[data_g2$procedure == "p2"]) mod_glm = glm(y1 ~ procedure, data = data_g2, family = binomial) summary(mod) mod_glmer = glmer(y1 ~ procedure + (1|id), data = data_g2, family = binomial) summary(mod_glmer) ,这是一个唯一标识位置的文本标识符。要通过ID获取位置,请调用placeID,并传递一个位置ID和一个回调方法。

因此,您需要声明另一个全局数组以保存placesID。或者,您可以使用一个数组保存GMSAutocompletePrediction对象;在cellForRowAtIndexPath中提取attributedFullText以填充标签,并在didSelectRow中提取placeID。

假设您的tableData是GMSAutocompletePrediction对象的数组。

GMSPlacesClient lookUpPlaceID:callback:

然后您的didAutocomplete委托方法将是这样

var tableData = [GMSAutocompletePrediction]()

您的cellForRowAtIndexPath将是:-

func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
    tableData = predictions
}

您的didSelectRowAt将为:-

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    /* Intitialise cell */

    let predictionText = tableData[indexPath.row]attributedFullText.string
    print(“Populate \(predictionText) in your cell labels”)

    /* Return cell */
}

您可以进一步了解here