我正在尝试通过坐标获取地点。
在Google Place API支持中类似功能..但我只想要像placeLikelihoodList这样的抓取位置对象。
有人知道这个吗?
我正在创建自己的函数“getCurrentPlace”
它返回了placeLikelihoodList,但我希望在特定坐标内获取placeLikelihoodList。
func reverseGeocodeCoordinate(coordinate: CLLocationCoordinate2D) {
//Create Lat/Lon
let geocoder = GMSGeocoder()
//get Location Address via LatLon
geocoder.reverseGeocodeCoordinate(coordinate) { response, error in
self.addressLbl.unlock()
self.placeCollectionView.reloadData()
if let address = response?.firstResult() {
if let lines = address.lines{
if (lines.count > 0) {
self.addressLbl.text = lines.joined(separator: "\n")
self.getCurrentPlace()
self.addressButton.setTitle(lines[0], forState: .Normal)
self.updateMapPadding()
}
}
UIView.animate(withDuration: 0.25) {
self.view.layoutIfNeeded()
}
}
}
}
func getNearByPlaces(coordinate: CLLocationCoordinate2D){
let center = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
let northEast = CLLocationCoordinate2D(latitude: center.latitude + 0.001, longitude: center.longitude + 0.001)
let southWest = CLLocationCoordinate2D(latitude: center.latitude - 0.001, longitude: center.longitude - 0.001)
let viewport = GMSCoordinateBounds(coordinate: northEast, coordinate: southWest)
let config = GMSPlacePickerConfig(viewport: viewport)
let placePicker = GMSPlacePicker(config: config)
placePicker.pickPlace(callback: {(place, error) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if place != nil {
// self.nameLabel.text = place.name
// self.addressLabel.text = place.formattedAddress?.components(separatedBy: ", ")
// .joined(separator: "\n")
print("nearBy")
// print(place.name)
//// print(place.formattedAddress?.components(separatedBy: ", ")
// .joined(separator: "\n"))
} else {
// self.nameLabel.text = "No place selected"
// self.addressLabel.text = ""
print("No place selected")
}
})
}
func getCurrentPlace(){
placesClient.currentPlace(callback: { (placeLikelihoodList, error) -> Void in
if let error = error {
print("Pick Place error: \(error.localizedDescription)")
return
}
if let placeLikelihoodList = placeLikelihoodList {
for likelihood in placeLikelihoodList.likelihoods {
let nearByPlace = PlaceCard()
let place = likelihood.place
nearByPlace.name = place.name
nearByPlace.id = place.placeID
nearByPlace.detail = place.formattedAddress
self.neayByPlaces.append(nearByPlace)
self.placeCollectionView.reloadData()
print("==============================================\(placeLikelihoodList.likelihoods.count)")
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)")
}
}
})
}