是否可以根据地点类型/类别过滤GMSPlacePicker [英] Is it possible to filter the GMSPlacePicker based on place type/category
问题描述
使用新的google将API放入ios中,是否可以根据地点类型/类别过滤通过GMSPlacePicker返回的结果。例如,如果我想返回附近的所有gas_station类型。
基本上,我正在寻找诸如GMSAutocompleteFilter之类的东西,但对于GMSPlacePicker。
您可以执行 HTTP Nearby Search Request,在请求参数中可以设置 types = gas_station
。在iOS中,您可以使用 NSURLSession
来执行http请求。 示例代码
let requestURL =https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362& radius = 2000& types = gas_station& key = YOUR_API_KEY
let request = NSURLRequest(URL:NSURL(string:requestURL)!)
let session = NSURLSession.sharedSession()
session.dataTaskWithRequest (请求,
completionHandler:{(data:NSData!,response:NSURLResponse!,error:NSError!)in
if error == nil {
let object = NSJSONSerialization。 JSONObjectWithData(data,options:nil,error:nil)as!NSDictionary
println(object)
让routes = object [results] as![NSDictionary]
for路线{
println(route [name])
}
}
else {
println(Places API error)
}
})。resume()
此请求将在 -33.8670522,151.1957362
附近的1000米范围内返回 gas_station
。
Using the new google places api for ios, is it possible to filter the results returned via GMSPlacePicker based on place type/category. For example, if I want to return all the gas_station types nearby.
Basically, I'm looking for something like GMSAutocompleteFilter, but for GMSPlacePicker.
You can do a HTTP Nearby Search Request, in the request parameter you can set the types=gas_station
. In iOS, you can use NSURLSession
to do a http request.
Sample code:
let requestURL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=2000&types=gas_station&key=YOUR_API_KEY"
let request = NSURLRequest(URL: NSURL(string:requestURL)!)
let session = NSURLSession.sharedSession()
session.dataTaskWithRequest(request,
completionHandler: {(data: NSData!, response: NSURLResponse!, error: NSError!) in
if error == nil {
let object = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as! NSDictionary
println(object)
let routes = object["results"] as! [NSDictionary]
for route in routes {
println(route["name"])
}
}
else {
println("Places API error")
}
}).resume()
This request will return the gas_station
within 1000 meters near -33.8670522,151.1957362
.
这篇关于是否可以根据地点类型/类别过滤GMSPlacePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!