我在我的某个应用程序中使用Google地方信息时,我需要查找附近的地点。地方' iOS API可以使用current place,也可以使用place picker。我不想要其中任何一个,但要传递坐标并到达附近的地方,因为我从图像中获取这些坐标。
答案 0 :(得分:0)
这将通过传递坐标返回附近的地方。只需调用此函数并传递坐标
即可func getPlacesUsingCoordinates(coordinate: CLLocationCoordinate2D, radius: Double, name : String){
//Pass name of place you want to search nearby in name
var urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=\(apiServerKey)&location=\(coordinate.latitude),\(coordinate.longitude)&radius=\(radius)&rankby=prominence&sensor=true"
urlString += "&name=\(name)"
urlString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
placesTask = session.dataTaskWithURL(NSURL(string: urlString)!) {data, response, error in
if let json = NSJSONSerialization.JSONObjectWithData(data, options:nil, error:nil) as? NSDictionary {
if let results = json["results"] as? NSArray {
if let name = results["name"] as? String {
print(name) //Place Name
}
if let location = results["geometry"]
print(location) //Geometry
}
}
}
self.placesTask.resume()
}
}
如果您想了解更多地方的详细信息,请使用:
CLGeocoder().reverseGeocodeLocation(yourLocation) { (placeDetails, error) in
// This provide every info related to location. Just pass yourLocation here
}
希望这是您正在寻找的。 strong>
答案 1 :(得分:0)
当电影院通过那个地方你应该得到类似餐馆,酒吧等的类型
<强>夫特强>
func fetchPlacesNearCoordinate(coordinate: CLLocationCoordinate2D, radius: Double, name : String){
let apiServerKey = "API-Key"
let urlString :URLRequest = URLRequest.init(url: URL.init(string: "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=\(apiServerKey)&location=\(currentlatitude),\(currentlongitude)&radius=\(radius)&types=\(Cinema)&rankby=prominence&sensor=true&name=\(Cinemas)")!)
print(urlString)
UIApplication.shared.isNetworkActivityIndicatorVisible = true
let placesTask = URLSession.shared.dataTask(with: urlString) {data, response, err in guard let data = data, err == nil else{
print("error ==>\(err)")
return
}
let responsestring = String(data: data, encoding: .utf8)
do {
let jsondata1 = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
print("Final data Convert to JSON =>\(jsondata1)")
let results = jsondata1["results"] as! NSArray
print("Results ==> \(results)")
}
catch{
print("error ==>\(err)")
}
}
placesTask.resume()
}