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
Binary file added Default-568h@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion SPGooglePlacesAutocomplete.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
31CA0C591A14344C0082C552 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 31CA0C581A14344C0082C552 /* Default-568h@2x.png */; };
9C4A632215B64A3F00E15FBA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C4A632115B64A3F00E15FBA /* UIKit.framework */; };
9C4A632415B64A3F00E15FBA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C4A632315B64A3F00E15FBA /* Foundation.framework */; };
9C4A632615B64A3F00E15FBA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C4A632515B64A3F00E15FBA /* CoreGraphics.framework */; };
Expand All @@ -28,6 +29,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
31CA0C581A14344C0082C552 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
9C4A631D15B64A3F00E15FBA /* SPGooglePlacesAutocomplete.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SPGooglePlacesAutocomplete.app; sourceTree = BUILT_PRODUCTS_DIR; };
9C4A632115B64A3F00E15FBA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
9C4A632315B64A3F00E15FBA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -76,6 +78,7 @@
9C4A631215B64A3F00E15FBA = {
isa = PBXGroup;
children = (
31CA0C581A14344C0082C552 /* Default-568h@2x.png */,
9C4A632715B64A3F00E15FBA /* SPGooglePlacesAutocomplete */,
9C4A632015B64A3F00E15FBA /* Frameworks */,
9C4A631E15B64A3F00E15FBA /* Products */,
Expand Down Expand Up @@ -172,7 +175,7 @@
9C4A631415B64A3F00E15FBA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0450;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Stephen Poletto";
};
buildConfigurationList = 9C4A631715B64A3F00E15FBA /* Build configuration list for PBXProject "SPGooglePlacesAutocomplete" */;
Expand Down Expand Up @@ -202,6 +205,7 @@
9C4A63A615B6C01100E15FBA /* location.png in Resources */,
9C4A63A715B6C01100E15FBA /* location@2x.png in Resources */,
9C4A63AE15B6C0DB00E15FBA /* locateButton.png in Resources */,
31CA0C591A14344C0082C552 /* Default-568h@2x.png in Resources */,
9C4A63AF15B6C0DB00E15FBA /* locateButton@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -258,6 +262,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
Expand Down Expand Up @@ -285,6 +290,7 @@
9C4A633615B64A3F00E15FBA /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SPGooglePlacesAutocomplete/SPGooglePlacesAutocomplete-Prefix.pch";
INFOPLIST_FILE = "SPGooglePlacesAutocomplete/SPGooglePlacesAutocomplete-Info.plist";
Expand All @@ -297,6 +303,7 @@
9C4A633715B64A3F00E15FBA /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SPGooglePlacesAutocomplete/SPGooglePlacesAutocomplete-Prefix.pch";
INFOPLIST_FILE = "SPGooglePlacesAutocomplete/SPGooglePlacesAutocomplete-Info.plist";
Expand Down Expand Up @@ -325,6 +332,7 @@
9C4A633715B64A3F00E15FBA /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>88E4F410-3060-491C-8448-75312C7744AE</string>
<key>IDESourceControlProjectName</key>
<string>SPGooglePlacesAutocomplete</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>3BAC43AA9CAA0E6DDD799DA562082A4246A801B0</key>
<string>github.com:vertigo/SPGooglePlacesAutocomplete.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>SPGooglePlacesAutocomplete.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>3BAC43AA9CAA0E6DDD799DA562082A4246A801B0</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>github.com:vertigo/SPGooglePlacesAutocomplete.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>3BAC43AA9CAA0E6DDD799DA562082A4246A801B0</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>3BAC43AA9CAA0E6DDD799DA562082A4246A801B0</string>
<key>IDESourceControlWCCName</key>
<string>SPGooglePlacesAutocomplete</string>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
<true/>
<key>SnapshotAutomaticallyBeforeSignificantChanges</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9C4A631C15B64A3F00E15FBA"
BuildableName = "SPGooglePlacesAutocomplete.app"
BlueprintName = "SPGooglePlacesAutocomplete"
ReferencedContainer = "container:SPGooglePlacesAutocomplete.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9C4A631C15B64A3F00E15FBA"
BuildableName = "SPGooglePlacesAutocomplete.app"
BlueprintName = "SPGooglePlacesAutocomplete"
ReferencedContainer = "container:SPGooglePlacesAutocomplete.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9C4A631C15B64A3F00E15FBA"
BuildableName = "SPGooglePlacesAutocomplete.app"
BlueprintName = "SPGooglePlacesAutocomplete"
ReferencedContainer = "container:SPGooglePlacesAutocomplete.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9C4A631C15B64A3F00E15FBA"
BuildableName = "SPGooglePlacesAutocomplete.app"
BlueprintName = "SPGooglePlacesAutocomplete"
ReferencedContainer = "container:SPGooglePlacesAutocomplete.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SPGooglePlacesAutocomplete.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>9C4A631C15B64A3F00E15FBA</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
9 changes: 2 additions & 7 deletions SPGooglePlacesAutocomplete/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ @implementation AppDelegate
@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

SPGooglePlacesAutocompleteViewController *viewController = [[[SPGooglePlacesAutocompleteViewController alloc] init] autorelease];
SPGooglePlacesAutocompleteViewController *viewController = [[SPGooglePlacesAutocompleteViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

return YES;
}

- (void)dealloc {
[window release];
[super dealloc];
}

@end
80 changes: 57 additions & 23 deletions SPGooglePlacesAutocomplete/SPGooglePlacesAutocompletePlace.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "SPGooglePlacesAutocompletePlace.h"
#import "SPGooglePlacesPlaceDetailQuery.h"

#import <MapKit/MapKit.h>

@interface SPGooglePlacesAutocompletePlace()
@property (nonatomic, retain, readwrite) NSString *name;
@property (nonatomic, retain, readwrite) NSString *reference;
Expand All @@ -21,10 +23,10 @@ @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"];
place.identifier = [placeDictionary objectForKey:@"place_id"];
place.type = SPPlaceTypeFromDictionary(placeDictionary);
return place;
}
Expand All @@ -41,22 +43,60 @@ - (CLGeocoder *)geocoder {
return geocoder;
}

- (void)resolveEstablishmentPlaceToPlacemark:(SPGooglePlacesPlacemarkResultBlock)block {
- (void)resolveReferenceIdentifierToPlacemark:(SPGooglePlacesPlacemarkResultBlock)block {
SPGooglePlacesPlaceDetailQuery *query = [SPGooglePlacesPlaceDetailQuery query];
query.reference = self.reference;
query.placeIdentifier = self.identifier;
[query fetchPlaceDetail:^(NSDictionary *placeDictionary, NSError *error) {
if (error) {
block(nil, nil, error);
} else {
NSString *addressString = [placeDictionary objectForKey:@"formatted_address"];
[[self geocoder] geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
block(nil, nil, error);
if (placeDictionary) {
NSString *placeAddress = [placeDictionary objectForKey:@"formatted_address"];
NSDictionary *placeGeometryDictionary = [placeDictionary objectForKey:@"geometry"];
NSDictionary *placeLocationDictionary = nil;
NSNumber *latitude = nil;
NSNumber *longitude = nil;

if (placeGeometryDictionary) {
placeLocationDictionary = [placeGeometryDictionary objectForKey:@"location"];
}

if (placeLocationDictionary) {
latitude = [placeLocationDictionary objectForKey:@"lat"];
longitude = [placeLocationDictionary objectForKey:@"lng"];
}

if (latitude && longitude) {
CLLocation *placeLocation = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];
[[self geocoder] reverseGeocodeLocation:placeLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
block(nil, nil, error);
} else {
CLPlacemark *placemark = [placemarks firstObject];
block(placemark, self.name, error);
}
}];
} else if (placeAddress) {
[[self geocoder] geocodeAddressString:placeAddress completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
block(nil, nil, error);
} else {
CLPlacemark *placemark = [placemarks firstObject];
block(placemark, self.name, error);
}
}];
} else {
CLPlacemark *placemark = [placemarks onlyObject];
block(placemark, self.name, error);
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey:NSLocalizedString(@"Could not resolve place.", nil) };
error = [[NSError alloc] initWithDomain:@"com.spoletto.googleplaces" code:kGoogleAPINSErrorCode userInfo:userInfo];

block(nil, self.name, error);
}
}];
} else {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey:NSLocalizedString(@"Could not resolve place.", nil) };
error = [[NSError alloc] initWithDomain:@"com.spoletto.googleplaces" code:kGoogleAPINSErrorCode userInfo:userInfo];

block(nil, self.name, error);
}
}
}];
}
Expand All @@ -66,27 +106,21 @@ - (void)resolveGecodePlaceToPlacemark:(SPGooglePlacesPlacemarkResultBlock)block
if (error) {
block(nil, nil, error);
} else {
CLPlacemark *placemark = [placemarks onlyObject];
CLPlacemark *placemark = [placemarks firstObject];
block(placemark, self.name, error);
}
}];
}

- (void)resolveToPlacemark:(SPGooglePlacesPlacemarkResultBlock)block {
if (type == SPPlaceTypeGeocode) {
if (self.identifier.length > 0) {
// If there is already a Google Place API reference number, there should
// not be a need to attempt to geocode using the (inexact) address.
[self resolveReferenceIdentifierToPlacemark:block];
} else {
// Geocode places already have their address stored in the 'name' field.
[self resolveGecodePlaceToPlacemark:block];
} else {
[self resolveEstablishmentPlaceToPlacemark:block];
}
}

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

@end
Loading