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
.