Skip to content

Commit

Permalink
make use of the core location data
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfonseca committed Mar 10, 2010
1 parent 6c014f4 commit 5503fc6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 10 deletions.
14 changes: 14 additions & 0 deletions Classes/CLLocation-Utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// CLLocation+Aditions.h
// Gowalla
//
// Created by Ruben Fonseca on 3/10/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <CoreLocation/CLLocation.h>

@interface CLLocation (Utilities)
- (NSDictionary *) betterCoordinates;
@end
19 changes: 19 additions & 0 deletions Classes/CLLocation-Utilities.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CLLocation+Aditions.m
// Gowalla
//
// Created by Ruben Fonseca on 3/10/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CLLocation-Utilities.h"


@implementation CLLocation (Aditions)
- (NSDictionary *)betterCoordinates {
NSMutableDictionary *res = [NSMutableDictionary dictionaryWithCapacity:2];
[res setObject:[NSNumber numberWithDouble:self.coordinate.latitude] forKey:@"latitude"];
[res setObject:[NSNumber numberWithDouble:self.coordinate.longitude] forKey:@"longitude"];
return res;
}
@end
6 changes: 6 additions & 0 deletions Classes/CLLocationAdditions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CLLocationAdditions.rb
# Gowalla
#
# Created by Ruben Fonseca on 3/10/10.
# Copyright 2010 __MyCompanyName__. All rights reserved.

32 changes: 22 additions & 10 deletions Classes/GowallaDelegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def applicationDidFinishLaunching(notification)
end

def applicationWillTerminate(notification)
@locationManager.stopUpdatingLocation
@locationManager.stopUpdatingLocation if @locationManager
end

# Credentials delegate
Expand All @@ -46,51 +46,63 @@ def submitCredentials(sender)
def hideCredentials(sender)
NSApp.endSheet(credentials_window)
credentials_window.orderOut(sender)
NSApp.terminate(sender)
end

# Webscript Callable methods
def searchAddress(northeast, southwest)
progressView.startAnimation(self)
@client.list_spots(:sw => southwest, :ne => northeast) do |response|
showSpots(response)
progressView.stopAnimation(self) unless @locationManager
end
end

def geocodeAddress(sender)
@locationManager.stopUpdatingLocation

progressView.startAnimation(self)
self.webView.stringByEvaluatingJavaScriptFromString("geocode(\"#{sender.stringValue}\");")
end

def updateMap(latitude, longitude)
@client.list_spots(:lat => latitude, :lng => longitude) do |response|
showSpots(response)
progressView.stopAnimation(self)
end
end

def checkin(spot_id, lat, lng)
progressView.startAnimation(self)
@client.checkin(:spot_id => spot_id, :lat => lat, :lng => lng) do |response|
CheckinResultView.new.showCheckin(main_window, response)
puts "Success :)"
progressView.stopAnimation(self)
NSLog("Success :)")
end
end

# WebScript informal protocol
def self.isSelectorExcludedFromWebScript(selector)
puts "excluded? #{selector}"
false
end

def self.isKeyExcludedFromWebScript(name)
puts "key? #{name}"
false
end

# Location delegate
def locationManager(manager, didUpdateToLocation:newLocation, fromLocation:oldLocation)
updateMap(newLocation.betterCoordinates['latitude'].doubleValue, newLocation.betterCoordinates['longitude'].doubleValue)
self.progressView.stopAnimation(self)
self.searchField.cell.setPlaceholderString("")

@locationManager.stopUpdatingLocation
@locationManager = nil
end

def locationManager(manager, didFailWithError:error)
puts error.localizedDescription
NSLog(error.localizedDescription)
self.progressView.stopAnimation(self)
self.searchField.cell.setPlaceholderString("Couldn't find your location")

@locationManager.stopUpdatingLocation
@locationManager = nil
end

private
Expand Down
10 changes: 10 additions & 0 deletions Gowalla.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
3EDC86AA1147EE6800605E37 /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = 3EDC86A81147EE6800605E37 /* index.html */; };
3EDC86C11147F34900605E37 /* NSStringAdditions.rb in Resources */ = {isa = PBXBuildFile; fileRef = 3EDC86C01147F34900605E37 /* NSStringAdditions.rb */; };
3EDC86F41147F60000605E37 /* find.js in Resources */ = {isa = PBXBuildFile; fileRef = 3EDC86A71147EE6800605E37 /* find.js */; };
3EDC87361147FA7100605E37 /* CLLocation-Utilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDC87351147FA7100605E37 /* CLLocation-Utilities.m */; };
3EDC877F1147FD5800605E37 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EDC877E1147FD5800605E37 /* CoreLocation.framework */; };
3EE2302E1141D34D00933AAB /* GowallaDelegate.rb in Resources */ = {isa = PBXBuildFile; fileRef = 3EE2302D1141D34D00933AAB /* GowallaDelegate.rb */; };
3EE230341141D39600933AAB /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EE230331141D39600933AAB /* WebKit.framework */; };
3EF000C7114587B300BCF241 /* Gems in Resources */ = {isa = PBXBuildFile; fileRef = 3EF000A8114587B300BCF241 /* Gems */; };
Expand Down Expand Up @@ -84,6 +86,9 @@
3EDC86A71147EE6800605E37 /* find.js */ = {isa = PBXFileReference; explicitFileType = sourcecode.javascript; fileEncoding = 4; name = find.js; path = Views/find.js; sourceTree = SOURCE_ROOT; };
3EDC86A81147EE6800605E37 /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = index.html; path = Views/index.html; sourceTree = SOURCE_ROOT; };
3EDC86C01147F34900605E37 /* NSStringAdditions.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = NSStringAdditions.rb; sourceTree = "<group>"; };
3EDC87341147FA7100605E37 /* CLLocation-Utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocation-Utilities.h"; sourceTree = "<group>"; };
3EDC87351147FA7100605E37 /* CLLocation-Utilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CLLocation-Utilities.m"; sourceTree = "<group>"; };
3EDC877E1147FD5800605E37 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = /System/Library/Frameworks/CoreLocation.framework; sourceTree = "<absolute>"; };
3EE2302D1141D34D00933AAB /* GowallaDelegate.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = GowallaDelegate.rb; sourceTree = "<group>"; };
3EE230331141D39600933AAB /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
3EF000A8114587B300BCF241 /* Gems */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Gems; sourceTree = "<group>"; };
Expand Down Expand Up @@ -114,6 +119,7 @@
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
4DE3BE140D8651D900ECA448 /* MacRuby.framework in Frameworks */,
3EE230341141D39600933AAB /* WebKit.framework in Frameworks */,
3EDC877F1147FD5800605E37 /* CoreLocation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -128,6 +134,8 @@
3E5468491144314300E45FA3 /* Gowalla.rb */,
3E76441A1147D0D500D49E69 /* CheckinResultView.rb */,
3EDC86C01147F34900605E37 /* NSStringAdditions.rb */,
3EDC87341147FA7100605E37 /* CLLocation-Utilities.h */,
3EDC87351147FA7100605E37 /* CLLocation-Utilities.m */,
);
path = Classes;
sourceTree = "<group>";
Expand All @@ -138,6 +146,7 @@
4DE3BE130D8651D900ECA448 /* MacRuby.framework */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
3EE230331141D39600933AAB /* WebKit.framework */,
3EDC877E1147FD5800605E37 /* CoreLocation.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
Expand Down Expand Up @@ -360,6 +369,7 @@
3EF5F5D1114463F4002ADC57 /* SBJsonBase.m in Sources */,
3EF5F5D2114463F4002ADC57 /* SBJsonParser.m in Sources */,
3EF5F5D3114463F4002ADC57 /* SBJsonWriter.m in Sources */,
3EDC87361147FA7100605E37 /* CLLocation-Utilities.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 5503fc6

Please sign in to comment.