【发布时间】:2016-01-22 00:14:58
【问题描述】:
我想使用 Google Places API 获取离当前用户最近的位置并保存它,最终创建一组保存的位置。由于在线谷歌文档不是很有帮助,我在自己弄清楚如何做这件事上遇到了一些麻烦。我已经有一个 CLLocationManager 工作正常,但是在同步所有内容时我不知所措。
谢谢!
当用户按下按钮时,我希望它调用一个方法并保存最近的当前位置...这是我目前所拥有的示例方法。
func saveInfoTestMethod() {
let placesClient = GMSPlacesClient?()
placesClient?.currentPlaceWithCallback({ (placeLikelihoods: GMSPlaceLikelihoodList?, error) -> Void in
if error != nil {
print("Current Place error: \(error!.localizedDescription)")
return
}
for likelihood in placeLikelihoods!.likelihoods {
if let likelihood = likelihood as? GMSPlaceLikelihood {
let place = likelihood.place
print("Current Place name \(place.name) at likelihood \(likelihood.likelihood)")
print("Current Place address \(place.formattedAddress)")
print("Current Place attributions \(place.attributions)")
print("Current PlaceID \(place.placeID)")
//Somehow work below code into here
}
}
})
let userAddedPlace = GMSUserAddedPlace()
placesClient?.addPlace(userAddedPlace, callback: { (place, error) -> Void in
print(place!.name)
print(place!.formattedAddress)
print(place!.coordinate)
print(place!.types)
print(place!.phoneNumber)
})
}
【问题讨论】:
-
“保存”一个地方是什么意思?您是否尝试记录用户去过的地方?
addPlace不会对此有所帮助。 (基本上,它是用于向 Google 地图添加地点,因此添加从 Google Places API 收到的地点不会有任何用处。) -
我的意思是从 google API 中检索一个位置并将它们保存到应用程序内的一个数组中,无论是 Parse 还是 Core Data。谷歌的文档非常缺乏,所以我觉得有点失落。
-
我添加了 Google 登录框架/功能,是否可以使用此功能将用户的当前位置/附近地点的名称保存到当前的 google 帐户?再次感谢。
标签: ios swift2 google-places-api