CCXGoogleNearbyPlaces
Why use CCXGoogleNearbyPlaces?
- I made this cocoapod for the use of Google Maps & integrating a way to search nearby places without the generic search controller that they provide. This give you the flexibility of making your own custom search UI.
- CCXGoogleNearbyPlaces gives you ALL the options using the API. It gives you the photo URL's for the places found as well as paging results, searching by a set type/category or custom category & search by text credientials.
- CCXGoogleNearbyPlaces does NOT use another other third party networking tools to complete the API calls.
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
From there, you may set a breakpoint in the AppDelegate where we call to the Nearby Places API and give a response & see if this is a cocoapod that could be of use for you.
Installation
CCXGoogleNearbyPlaces is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CCXGoogleNearbyPlaces'
Integration
You need an API key
Once you have downloaded and successfully built the module, go to your AppDelegate file and import the CCXGoogleNearlyPlaces module.
You will then need to go and make sure you have an API key to use the cocoapod. Please reference the following to obtain your API key:
Configuring your API key
Once you have obtained a valid API key from the link above, you will set your api key as the following:
CCXGoogleSDK.places.apiKey = "Your API Key"
Usage Details
There are a few ways you can fetch results with the CCXGoogleNearbyPlaces pod. You may use a text parameter with a distance, from a location. The API returns 20 results. In the response object we will indicate whether or not you can load more objects. You may load the next page by only passing in the next page token on your next request.
Usage Examples
Get all the nearby places with a radius & a location coordinate, and a text parameter:
let coord = CLLocationCoordinate2D()
// Radius is in meters.
CCXGoogleSDK.places.get(withText: "restaurants", withRadius: 300.4, coordinate: coord) { response in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
self.queueForNextLoad = true
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
Get all the nearby places with only a radius & a location coordinate:
let coord = CLLocationCoordinate2D()
// Radius is in meters.
CCXGoogleSDK.places.get(withRadius: 300.4, coordinate: coord) { response in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
self.queueForNextLoad = true
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
Get all the nearby places with your next page token:
CCXGoogleSDK.places.get(pageToken: "nextPageToken") { (response) in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
self.queueForNextLoad = true
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
Get places around you with a specific type or category:
CCXGoogleSDK.places.get(withRadius: 200.4, coordinate: coord, category: .hairCare) { (response) in
if response.status.isSuccess {
if response.places.isNotNil {
if response.canLoadMore {
// You should only use the pageToken in the get function on your next request.
}
// Deal with the places:
print(response.places!)
}
} else if response.error.isNotNil {
//
print(response.error!)
}
}
More
Google Documentation links:
Author
ryancoyne, [email protected]
License
CCXGoogleNearbyPlaces is available under the MIT license. See the LICENSE file for more info.