Skip to content

Commit

Permalink
replace location with coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsokolov committed Nov 27, 2014
1 parent 0338b4b commit 938bf5d
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 45 deletions.
4 changes: 2 additions & 2 deletions GoogleKit.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "GoogleKit"
s.version = "0.3"
s.version = "0.3.1"
s.summary = "An objective-c wrapper around the various Google API's"
s.homepage = "https://github.com/maxsokolov/GoogleKit"
s.license = { :type => "MIT", :file => "LICENSE" }
s.authors = { "Max Sokolov" => "[email protected]" }
s.social_media_url = "https://twitter.com/max_sokolov"
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/maxsokolov/GoogleKit.git", :tag => "0.3" }
s.source = { :git => "https://github.com/maxsokolov/GoogleKit.git", :tag => "0.3.1" }
s.source_files = "GoogleKit"
s.requires_arc = true
end
2 changes: 1 addition & 1 deletion GoogleKit/GKGeocoderPlace.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
@property (nonatomic, strong, readonly) NSString *streetNumber;
@property (nonatomic, strong, readonly) NSString *floor;
@property (nonatomic, strong, readonly) NSString *room;
@property (nonatomic, strong, readonly) CLLocation *location;
@property (nonatomic, assign, readonly) CLLocationCoordinate2D coordinate;

@end
2 changes: 1 addition & 1 deletion GoogleKit/GKGeocoderPlace.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {
CGFloat lat = [[[[dictionary objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lat"] floatValue];
CGFloat lng = [[[[dictionary objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lng"] floatValue];

_location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
_coordinate = CLLocationCoordinate2DMake(lat, lng);
}
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKGeocoderQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//@property (nonatomic, strong) NSArray *bounds;

// Reverse Geocoding (Address Lookup)
@property (nonatomic, assign) CLLocationCoordinate2D location;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, strong) NSArray *locationType;
@property (nonatomic, strong) NSArray *resultType;
@property (nonatomic, strong) NSString *postalCode;
Expand Down
6 changes: 3 additions & 3 deletions GoogleKit/GKGeocoderQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (id)init {
self = [super init];
if (self) {

self.location = kCLLocationCoordinate2DInvalid;
self.coordinate = kCLLocationCoordinate2DInvalid;
}
return self;
}
Expand All @@ -48,8 +48,8 @@ - (NSURL *)queryURL {

if (self.isReverseGeocoding) {

if (CLLocationCoordinate2DIsValid(self.location)) {
[url appendFormat:@"&latlng=%f,%f", self.location.latitude, self.location.longitude];
if (CLLocationCoordinate2DIsValid(self.coordinate)) {
[url appendFormat:@"&latlng=%f,%f", self.coordinate.latitude, self.coordinate.longitude];
}
if (self.resultType && self.resultType.count > 0) {
[url appendFormat:@"&result_type=%@", [self.resultType componentsJoinedByString:@"|"]];
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlace.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@interface GKPlace : GKObject

@property (nonatomic, strong, readonly) NSString *formattedAddress;
@property (nonatomic, strong, readonly) CLLocation *location;
@property (nonatomic, assign, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, strong, readonly) NSString *icon;
@property (nonatomic, strong, readonly) NSString *name;
@property (nonatomic, assign, readonly) CGFloat rating;
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlace.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {
CGFloat lat = [[[[dictionary objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lat"] floatValue];
CGFloat lng = [[[[dictionary objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lng"] floatValue];

_location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
_coordinate = CLLocationCoordinate2DMake(lat, lng);

_icon = [dictionary objectForKey:@"icon"];
_name = [dictionary objectForKey:@"name"];
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlaceAutocompleteQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@property (nonatomic, strong) NSString *input;
@property (nonatomic, assign) NSUInteger offset;
@property (nonatomic, assign) NSUInteger radius;
@property (nonatomic, assign) CLLocationCoordinate2D location;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;

/*
* Description
Expand Down
6 changes: 3 additions & 3 deletions GoogleKit/GKPlaceAutocompleteQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (id)init {

self.radius = 10000.0f;
self.offset = 0;
self.location = kCLLocationCoordinate2DInvalid;
self.coordinate = kCLLocationCoordinate2DInvalid;
}
return self;
}
Expand All @@ -60,8 +60,8 @@ - (NSURL *)queryURL {
if (self.offset != 0) {
[url appendFormat:@"&offset=%@", @(self.offset)];
}
if (self.location.latitude != -1) {
[url appendFormat:@"&location=%f,%f", self.location.latitude, self.location.longitude];
if (self.coordinate.latitude != -1) {
[url appendFormat:@"&location=%f,%f", self.coordinate.latitude, self.coordinate.longitude];
}
if (self.radius != 0) {
[url appendFormat:@"&radius=%@", @(self.radius)];
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlaceDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
@property (nonatomic, strong, readonly) NSURL *url;
@property (nonatomic, strong, readonly) NSURL *website;
@property (nonatomic, assign, readonly) CGFloat rating;
@property (nonatomic, strong, readonly) CLLocation *location;
@property (nonatomic, assign, readonly) CLLocationCoordinate2D coordinate;

@end
2 changes: 1 addition & 1 deletion GoogleKit/GKPlaceDetails.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {

CGFloat lat = [[[[dictionary objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lat"] floatValue];
CGFloat lng = [[[[dictionary objectForKey:@"geometry"] objectForKey:@"location"] objectForKey:@"lng"] floatValue];
_location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
_coordinate = CLLocationCoordinate2DMake(lat, lng);

_icon = [dictionary objectForKey:@"icon"];
_name = [dictionary objectForKey:@"name"];
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlacesNearbySearchQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef void (^GKPlacesNearbySearchQueryCompletionBlock)(NSArray *results, NSStr
@interface GKPlacesNearbySearchQuery : GKQuery

// required parameters
@property (nonatomic, assign) CLLocationCoordinate2D location;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSUInteger radius;

// optional parameters
Expand Down
6 changes: 3 additions & 3 deletions GoogleKit/GKPlacesNearbySearchQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (id)init {
self.maxprice = -1;
self.radius = -1;
self.rankByDistance = NO;
self.location = kCLLocationCoordinate2DInvalid;
self.coordinate = kCLLocationCoordinate2DInvalid;
}
return self;
}
Expand All @@ -56,8 +56,8 @@ - (NSURL *)queryURL {
return [NSURL URLWithString:url];
}

if (CLLocationCoordinate2DIsValid(self.location)) {
[url appendFormat:@"&location=%f,%f", self.location.latitude, self.location.longitude];
if (CLLocationCoordinate2DIsValid(self.coordinate)) {
[url appendFormat:@"&location=%f,%f", self.coordinate.latitude, self.coordinate.longitude];
}
if (self.rankByDistance) {
[url appendString:@"&rankby=distance"];
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlacesRadarSearchQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef void (^GKPlacesRadarSearchQueryCompletionBlock)(NSArray *results, NSErro
@interface GKPlacesRadarSearchQuery : GKQuery

// required parameters
@property (nonatomic, assign) CLLocationCoordinate2D location;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSUInteger radius;

// optional parameters
Expand Down
6 changes: 3 additions & 3 deletions GoogleKit/GKPlacesRadarSearchQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (id)init {
self.minprice = -1;
self.maxprice = -1;
self.radius = -1;
self.location = kCLLocationCoordinate2DInvalid;
self.coordinate = kCLLocationCoordinate2DInvalid;
}
return self;
}
Expand All @@ -49,8 +49,8 @@ - (NSURL *)queryURL {

NSMutableString *url = [NSMutableString stringWithFormat:kGKPlacesRadarSearchQueryURL, self.key];

if (CLLocationCoordinate2DIsValid(self.location)) {
[url appendFormat:@"&location=%f,%f", self.location.latitude, self.location.longitude];
if (CLLocationCoordinate2DIsValid(self.coordinate)) {
[url appendFormat:@"&location=%f,%f", self.coordinate.latitude, self.coordinate.longitude];
}
if (self.radius != -1) {
[url appendFormat:@"&radius=%@", @(self.radius)];
Expand Down
2 changes: 1 addition & 1 deletion GoogleKit/GKPlacesTextSearchQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef void (^GKPlacesTextSearchQueryCompletionBlock)(NSArray *results, NSError
@property (nonatomic, strong) NSString *text; // becomes "query" param in request url

// optional parameters
@property (nonatomic, assign) CLLocationCoordinate2D location;
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) NSUInteger radius;
@property (nonatomic, assign) NSUInteger minprice; // 0...4
@property (nonatomic, assign) NSUInteger maxprice; // 0...4
Expand Down
6 changes: 3 additions & 3 deletions GoogleKit/GKPlacesTextSearchQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (id)init {
self.minprice = -1;
self.maxprice = -1;
self.radius = -1;
self.location = kCLLocationCoordinate2DInvalid;
self.coordinate = kCLLocationCoordinate2DInvalid;
}
return self;
}
Expand All @@ -46,8 +46,8 @@ - (NSURL *)queryURL {
if (self.text) {
[url appendFormat:@"&query=%@", [self.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
if (CLLocationCoordinate2DIsValid(self.location)) {
[url appendFormat:@"&location=%f,%f", self.location.latitude, self.location.longitude];
if (CLLocationCoordinate2DIsValid(self.coordinate)) {
[url appendFormat:@"&location=%f,%f", self.coordinate.latitude, self.coordinate.longitude];
}
if (self.radius != -1) {
[url appendFormat:@"&radius=%@", @(self.radius)];
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion GoogleKitDemo/GoogleKitDemo/GKAutocompleteViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void)textFieldDidChange:(UITextField *)textField {

GKPlaceAutocompleteQuery *query = [GKPlaceAutocompleteQuery query];
query.input = textField.text;
query.location = CLLocationCoordinate2DMake(55.738407f, 37.612306f); // New York City
query.coordinate = CLLocationCoordinate2DMake(55.738407f, 37.612306f); // New York City
query.types = @[ @"geocode" ];
query.radius = 10000;
[query fetchPlaces:^(NSArray *results, NSError *error) {
Expand Down
2 changes: 1 addition & 1 deletion GoogleKitDemo/GoogleKitDemo/GKMapGeocoderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
CLLocationCoordinate2D coord = [mapView convertPoint:self.view.center toCoordinateFromView:self.view];

GKGeocoderQuery *query = [GKGeocoderQuery query];
query.location = coord;
query.coordinate = coord;
query.language = @"en";
[query lookupAddress:^(NSArray *result, NSError *error) {

Expand Down
4 changes: 2 additions & 2 deletions GoogleKitDemo/GoogleKitDemo/GKNearbySearchViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)loadPlaces {
query.radius = 3000;
query.types = @[ @"library" ];
query.rankByDistance = NO;
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f); // New York City
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f); // New York City
query.nextPageToken = self.nextPageToken;

[query searchPlaces:^(NSArray *results, NSString *nextPageToken, NSError *error) {
Expand All @@ -69,7 +69,7 @@ - (void)buildAnnotations:(NSArray *)places {

for (GKPlace *place in places) {

GKMapAnnotation *annotation = [[GKMapAnnotation alloc] initWithCoordinate:place.location.coordinate placeId:place.placeId];
GKMapAnnotation *annotation = [[GKMapAnnotation alloc] initWithCoordinate:place.coordinate placeId:place.placeId];
[self.mapView addAnnotation:annotation];
}
}
Expand Down
2 changes: 1 addition & 1 deletion GoogleKitDemo/GoogleKitDemo/GKRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)viewDidLoad {

[GKQuery provideAPIKey:GOOGLE_API_KEY];
[GKQuery loggingEnabled:YES];

self.dataSource = @[@"Geocoder", @"Autocomplete places", @"Nearby Search & Place Details", @"Text search"];

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
Expand Down
Binary file not shown.
16 changes: 10 additions & 6 deletions GoogleKitTests/GoogleKitTests/GoogleKitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (void)testLocationGeocoder {

GKGeocoderQuery *query = [GKGeocoderQuery query];
query.key = kGoogleKitKey;
query.location = CLLocationCoordinate2DMake(55.738407f, 37.612306f);
query.coordinate = CLLocationCoordinate2DMake(55.738407f, 37.612306f);
query.language = @"en";
query.resultType = @[ @"street_address" ];
query.locationType = @[ @"ROOFTOP" ];
Expand All @@ -92,7 +92,7 @@ - (void)testNearbySearch {

GKPlacesNearbySearchQuery *query = [GKPlacesNearbySearchQuery query];
query.key = kGoogleKitKey;
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.rankByDistance = NO;
query.radius = 3000;
query.language = @"en";
Expand Down Expand Up @@ -122,7 +122,7 @@ - (void)testTextSearch {
query.key = kGoogleKitKey;
query.text = @"library";
query.language = @"en";
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.radius = 3000;
query.minprice = 0;
query.maxprice = 4;
Expand All @@ -146,7 +146,7 @@ - (void)testRadarSearch {

GKPlacesRadarSearchQuery *query = [GKPlacesRadarSearchQuery query];
query.key = kGoogleKitKey;
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.radius = 3000;
query.language = @"en";
query.keyword = @"library";
Expand Down Expand Up @@ -174,7 +174,7 @@ - (void)testPlaceAutocomplete {
GKPlaceAutocompleteQuery *query = [GKPlaceAutocompleteQuery query];
query.key = kGoogleKitKey;
query.input = @"wall street";
query.location = CLLocationCoordinate2DMake(55.738407f, 37.612306f);
query.coordinate = CLLocationCoordinate2DMake(55.738407f, 37.612306f);
query.types = @[ @"geocode" ];
query.components = @[ @"country:us" ];
query.radius = 10000;
Expand All @@ -199,7 +199,7 @@ - (void)testPlaceDetails {
GKPlaceAutocompleteQuery *query = [GKPlaceAutocompleteQuery query];
query.key = kGoogleKitKey;
query.input = @"wall street";
query.location = CLLocationCoordinate2DMake(55.738407f, 37.612306f);
query.coordinate = CLLocationCoordinate2DMake(55.738407f, 37.612306f);
query.types = @[ @"geocode" ];
query.components = @[ @"country:us" ];
query.radius = 10000;
Expand All @@ -208,6 +208,10 @@ - (void)testPlaceDetails {
[query fetchPlaces:^(NSArray *results, NSError *error) {

GKPlaceAutocomplete *place = [results firstObject];

XCTAssertNil(error);
XCTAssertTrue(results.count > 0);
XCTAssertTrue([place isKindOfClass:[GKPlaceAutocomplete class]]);

GKPlaceDetailsQuery *query = [GKPlaceDetailsQuery query];
query.key = kGoogleKitKey;
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Supports iOS 7 and higher. ARC is required.

GoogleKit is available via CocoaPods. Simply add the following line to your Podfile:

pod "GoogleKit", "0.3"
pod "GoogleKit", "~> 0.3"

## Usage

Expand Down Expand Up @@ -73,7 +73,7 @@ GKGeocoderQuery *query = [GKGeocoderQuery query];

// required parameters
query.key = @"key";
query.location = CLLocationCoordinate2DMake(0.0f, 0.0f);
query.coordinate = CLLocationCoordinate2DMake(0.0f, 0.0f);

// optional parameters
query.language = @"en";
Expand All @@ -100,7 +100,7 @@ query.key = @"key";
query.input = @"wall street";
// optional parameters
query.location = CLLocationCoordinate2DMake(55.738407f, 37.612306f); // New York City
query.coordinate = CLLocationCoordinate2DMake(55.738407f, 37.612306f); // New York City
query.types = @[ @"geocode" ];
query.components = @[ @"country:us" ];
query.radius = 10000;
Expand All @@ -123,7 +123,7 @@ GKPlacesNearbySearchQuery *query = [GKPlacesNearbySearchQuery query];

// required parameters
query.key = @"key";
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f); // New York City
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f); // New York City
query.rankByDistance = NO; // if rankByDistance sets to YES radius will be ignored
query.radius = 3000;

Expand Down Expand Up @@ -157,7 +157,7 @@ query.text = @"pizza in New York";
// optional parameters
query.language = @"en";
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f);
query.radius = 3000;
query.minprice = 0;
query.maxprice = 4;
Expand All @@ -180,7 +180,7 @@ GKPlacesRadarSearchQuery *query = [GKPlacesRadarSearchQuery query];

// required parameters
query.key = @"key";
query.location = CLLocationCoordinate2DMake(40.71448f, -74.00598f); // New York City
query.coordinate = CLLocationCoordinate2DMake(40.71448f, -74.00598f); // New York City
query.radius = 3000;

// optional parameters
Expand Down

0 comments on commit 938bf5d

Please sign in to comment.