Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/*!
Contains the human-readable name for the returned result. For establishment results, this is usually the business name.
*/
@property (nonatomic, retain, readonly) NSString *name;
@property (nonatomic, strong, readonly) NSString *name;

/*!
Contains the primary 'type' of this place (i.e. "establishment" or "gecode").
Expand All @@ -29,12 +29,12 @@
/*!
Contains a unique token that you can use to retrieve additional information about this place in a Place Details request. You can store this token and use it at any time in future to refresh cached data about this Place, but the same token is not guaranteed to be returned for any given Place across different searches.
*/
@property (nonatomic, retain, readonly) NSString *reference;
@property (nonatomic, strong, readonly) NSString *reference;

/*!
Contains a unique stable identifier denoting this place. This identifier may not be used to retrieve information about this place, but can be used to consolidate data about this Place, and to verify the identity of a Place across separate searches.
*/
@property (nonatomic, retain, readonly) NSString *identifier;
@property (nonatomic, strong, readonly) NSString *identifier;

/*!
Resolves the place to a CLPlacemark, issuing Google Place Details request if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#import "SPGooglePlacesPlaceDetailQuery.h"

@interface SPGooglePlacesAutocompletePlace()
@property (nonatomic, retain, readwrite) NSString *name;
@property (nonatomic, retain, readwrite) NSString *reference;
@property (nonatomic, retain, readwrite) NSString *identifier;
@property (nonatomic, strong, readwrite) NSString *name;
@property (nonatomic, strong, readwrite) NSString *reference;
@property (nonatomic, strong, readwrite) NSString *identifier;
@property (nonatomic, readwrite) SPGooglePlacesAutocompletePlaceType type;
@end

Expand All @@ -21,7 +21,7 @@ @implementation SPGooglePlacesAutocompletePlace
@synthesize name, reference, identifier, type;

+ (SPGooglePlacesAutocompletePlace *)placeFromDictionary:(NSDictionary *)placeDictionary {
SPGooglePlacesAutocompletePlace *place = [[[self alloc] init] autorelease];
SPGooglePlacesAutocompletePlace *place = [[self alloc] init];
place.name = [placeDictionary objectForKey:@"description"];
place.reference = [placeDictionary objectForKey:@"reference"];
place.identifier = [placeDictionary objectForKey:@"id"];
Expand Down Expand Up @@ -81,12 +81,5 @@ - (void)resolveToPlacemark:(SPGooglePlacesPlacemarkResultBlock)block {
}
}

- (void)dealloc {
[name release];
[reference release];
[identifier release];
[geocoder release];
[super dealloc];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/*!
The text string on which to search. The Place service will return candidate matches based on this string and order results based on their perceived relevance. Defaults to nil.
*/
@property (nonatomic, retain) NSString *input;
@property (nonatomic, strong) NSString *input;

/*!
Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. This value must be either true or false. Defaults to YES.
Expand All @@ -40,7 +40,7 @@
/*!
Your application's API key. This key identifies your application for purposes of quota management. Visit the APIs Console to select an API Project and obtain your key. Maps API for Business customers must use the API project created for them as part of their Places for Business purchase. Defaults to kGoogleAPIKey.
*/
@property (nonatomic, retain) NSString *key;
@property (nonatomic, strong) NSString *key;

#pragma mark -
#pragma mark Optional parameters
Expand All @@ -53,7 +53,7 @@
/*!
The point around which you wish to retrieve Place information.
*/
@property (nonatomic) CLLocationCoordinate2D location;
@property (nonatomic, strong) CLLocation *location;

/*!
The distance (in meters) within which to return Place results. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area.
Expand All @@ -63,7 +63,7 @@
/*!
The language in which to return results. See the supported list of domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the Place service will attempt to use the native language of the domain from which the request is sent.
*/
@property (nonatomic, retain) NSString *language;
@property (nonatomic, strong) NSString *language;

/*!
The types of Place results to return. If no type is specified, all types will be returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ @implementation SPGooglePlacesAutocompleteQuery
@synthesize input, sensor, key, offset, location, radius, language, types, resultBlock;

+ (SPGooglePlacesAutocompleteQuery *)query {
return [[[self alloc] init] autorelease];
return [[self alloc] init];
}

- (id)init {
Expand All @@ -28,7 +28,7 @@ - (id)init {
self.sensor = YES;
self.key = kGoogleAPIKey;
self.offset = NSNotFound;
self.location = CLLocationCoordinate2DMake(-1, -1);
self.location = nil;
self.radius = NSNotFound;
self.types = -1;
}
Expand All @@ -39,14 +39,6 @@ - (NSString *)description {
return [NSString stringWithFormat:@"Query URL: %@", [self googleURLString]];
}

- (void)dealloc {
[googleConnection release];
[responseData release];
[input release];
[key release];
[language release];
[super dealloc];
}

- (NSString *)googleURLString {
NSMutableString *url = [NSMutableString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&sensor=%@&key=%@",
Expand All @@ -55,8 +47,8 @@ - (NSString *)googleURLString {
if (offset != NSNotFound) {
[url appendFormat:@"&offset=%u", offset];
}
if (location.latitude != -1) {
[url appendFormat:@"&location=%f,%f", location.latitude, location.longitude];
if (self.location) {
[url appendFormat:@"&location=%f,%f", self.location.coordinate.latitude, self.location.coordinate.longitude];
}
if (radius != NSNotFound) {
[url appendFormat:@"&radius=%f", radius];
Expand All @@ -71,8 +63,6 @@ - (NSString *)googleURLString {
}

- (void)cleanup {
[googleConnection release];
[responseData release];
googleConnection = nil;
responseData = nil;
self.resultBlock = nil;
Expand All @@ -84,7 +74,7 @@ - (void)cancelOutstandingRequests {
}

- (void)fetchPlaces:(SPGooglePlacesAutocompleteResultBlock)block {
if (!SPEnsureGoogleAPIKey()) {
if (!SPEnsureGoogleAPIKey(self.key)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ SPGooglePlacesAutocompletePlaceType SPPlaceTypeFromDictionary(NSDictionary *plac
return (type == SPPlaceTypeGeocode) ? @"geocode" : @"establishment";
}

BOOL SPEnsureGoogleAPIKey() {
BOOL SPEnsureGoogleAPIKey(NSString *key) {
BOOL userHasProvidedAPIKey = YES;
if ([kGoogleAPIKey isEqualToString:@"YOUR_API_KEY"]) {
if ([key isEqualToString:@"YOUR_API_KEY"] || [key isEqualToString:@""] || !key) {
userHasProvidedAPIKey = NO;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"API Key Needed" message:@"Please replace kGoogleAPIKey with your Google API key." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
return userHasProvidedAPIKey;
}

void SPPresentAlertViewWithErrorAndTitle(NSError *error, NSString *title) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}

extern BOOL SPIsEmptyString(NSString *string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
BOOL shouldBeginEditing;
}

@property (retain, nonatomic) IBOutlet MKMapView *mapView;
@property (strong, nonatomic) IBOutlet MKMapView *mapView;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ - (void)viewDidUnload {
[super viewDidUnload];
}

- (void)dealloc {
[selectedPlaceAnnotation release];
[mapView release];
[searchQuery release];
[super dealloc];
}

- (IBAction)recenterMapToUserLocation:(id)sender {
MKCoordinateRegion region;
Expand Down Expand Up @@ -71,7 +65,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
static NSString *cellIdentifier = @"SPGooglePlacesAutocompleteCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

cell.textLabel.font = [UIFont fontWithName:@"GillSans" size:16.0];
Expand All @@ -97,7 +91,6 @@ - (void)recenterMapToPlacemark:(CLPlacemark *)placemark {

- (void)addPlacemarkAnnotationToMap:(CLPlacemark *)placemark addressString:(NSString *)address {
[self.mapView removeAnnotation:selectedPlaceAnnotation];
[selectedPlaceAnnotation release];

selectedPlaceAnnotation = [[MKPointAnnotation alloc] init];
selectedPlaceAnnotation.coordinate = placemark.location.coordinate;
Expand Down Expand Up @@ -135,14 +128,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
#pragma mark UISearchDisplayDelegate

- (void)handleSearchForSearchString:(NSString *)searchString {
searchQuery.location = self.mapView.userLocation.coordinate;
searchQuery.location = self.mapView.userLocation.location;
searchQuery.input = searchString;
[searchQuery fetchPlaces:^(NSArray *places, NSError *error) {
if (error) {
SPPresentAlertViewWithErrorAndTitle(error, @"Could not fetch Places");
} else {
[searchResultPlaces release];
searchResultPlaces = [places retain];
searchResultPlaces = places;
[self.searchDisplayController.searchResultsTableView reloadData];
}
}];
Expand Down Expand Up @@ -193,7 +185,7 @@ - (MKAnnotationView *)mapView:(MKMapView *)mapViewIn viewForAnnotation:(id <MKAn
static NSString *annotationIdentifier = @"SPGooglePlacesAutocompleteAnnotation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!annotationView) {
annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
}
annotationView.animatesDrop = YES;
annotationView.canShowCallout = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/*!
A textual identifier that uniquely identifies a place, returned from a Place search request.
*/
@property (nonatomic, retain) NSString *reference;
@property (nonatomic, strong) NSString *reference;

/*!
Indicates whether or not the Place request came from a device using a location sensor (e.g. a GPS) to determine the location sent in this request. This value must be either true or false. Defaults to YES.
Expand All @@ -38,14 +38,14 @@
/*!
Your application's API key. This key identifies your application for purposes of quota management. Visit the APIs Console to select an API Project and obtain your key. Maps API for Business customers must use the API project created for them as part of their Places for Business purchase. Defaults to kGoogleAPIKey.
*/
@property (nonatomic, retain) NSString *key;
@property (nonatomic, strong) NSString *key;

#pragma mark -
#pragma mark Optional parameters

/*!
The language in which to return results. See the supported list of domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the Place service will attempt to use the native language of the domain from which the request is sent.
*/
@property (nonatomic, retain) NSString *language;
@property (nonatomic, strong) NSString *language;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ @implementation SPGooglePlacesPlaceDetailQuery
@synthesize reference, sensor, key, language, resultBlock;

+ (SPGooglePlacesPlaceDetailQuery *)query {
return [[[self alloc] init] autorelease];
return [[self alloc] init];
}

- (id)init {
Expand All @@ -34,14 +34,6 @@ - (NSString *)description {
return [NSString stringWithFormat:@"Query URL: %@", [self googleURLString]];
}

- (void)dealloc {
[googleConnection release];
[responseData release];
[reference release];
[key release];
[language release];
[super dealloc];
}

- (NSString *)googleURLString {
NSMutableString *url = [NSMutableString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/details/json?reference=%@&sensor=%@&key=%@",
Expand All @@ -53,8 +45,6 @@ - (NSString *)googleURLString {
}

- (void)cleanup {
[googleConnection release];
[responseData release];
googleConnection = nil;
responseData = nil;
self.resultBlock = nil;
Expand All @@ -66,7 +56,7 @@ - (void)cancelOutstandingRequests {
}

- (void)fetchPlaceDetail:(SPGooglePlacesPlaceDetailResultBlock)block {
if (!SPEnsureGoogleAPIKey()) {
if (!SPEnsureGoogleAPIKey(self.key)) {
return;
}

Expand Down
13 changes: 13 additions & 0 deletions SPGooglePlacesAutocomplete.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Pod::Spec.new do |s|
s.name = "SPGooglePlacesAutocomplete"
s.version = "1.0.2"
s.summary = "An objective-c wrapper around the Google Places autocomplete API. Includes sample application emulating the Maps app."
s.homepage = "https://github.com/chrischentickbox/SPGooglePlacesAutocomplete"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.authors = { "Matej Bukovinski" => "matej@bukovinski.com", "Chris Chen" => "chrischen79@gmail.com" }
s.platform = :ios, '6.0'
s.source = { :git => "https://github.com/chrischentickbox/SPGooglePlacesAutocomplete.git", :tag => '1.0.2'}
s.source_files = 'Library/*.{h,m}'
s.frameworks = 'CoreLocation'
s.requires_arc = true
end
Loading