Permalink
Browse files

Stop the manager and return nil for no location

  • Loading branch information...
1 parent 8a1ed16 commit 255525a7055b8722a915eb8cddb08eedcd7a07f8 @evanphx committed Aug 7, 2012
Showing with 30 additions and 6 deletions.
  1. +26 −4 ext/lost/core_loc.m
  2. +4 −2 ext/lost/lost.c
View
@@ -14,8 +14,11 @@
@interface LLHolder : NSObject {
double latitude;
double longitude;
+ int worked;
}
+- (void)reset;
+- (int)useData;
- (void)latitude:(double*)lat longitude:(double*)log;
- (void)logLonLat:(CLLocation*)location;
@@ -25,6 +28,17 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
@end
@implementation LLHolder
+
+- (void)reset
+{
+ worked = 0;
+}
+
+- (int)useData
+{
+ return worked;
+}
+
- (void)latitude:(double*)lat longitude:(double*)log
{
*lat = latitude;
@@ -33,6 +47,7 @@ - (void)latitude:(double*)lat longitude:(double*)log
- (void)logLonLat:(CLLocation*)location
{
+ worked = 1;
CLLocationCoordinate2D coordinate = location.coordinate;
latitude = coordinate.latitude;
longitude = coordinate.longitude;
@@ -47,7 +62,7 @@ - (void)locationManager:(CLLocationManager *)manager
[pool drain];
}
-- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
+- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
latitude = 0.0;
longitude = 0.0;
CFRunLoopStop(CFRunLoopGetCurrent());
@@ -65,16 +80,23 @@ int int_coreloc_enable() {
return 0;
}
-void int_coreloc_get(double* lat, double* log) {
+int int_coreloc_get(double* lat, double* log) {
LLHolder* obj = [[LLHolder alloc] init];
[g_lm setDelegate:obj];
[g_lm startUpdatingLocation];
CFRunLoopRun();
- [obj release];
+ [g_lm stopUpdatingLocation];
+
+ if([obj useData] == 1) {
+ [obj latitude: lat longitude: log];
+ [obj release];
+ return 1;
+ }
- [obj latitude: lat longitude: log];
+ [obj release];
+ return 0;
}
// int main(int ac,char *av[])
View
@@ -7,7 +7,7 @@
#endif
int int_coreloc_enable();
-void int_coreloc_get(double* lat, double* log);
+int int_coreloc_get(double* lat, double* log);
VALUE coreloc_enable(VALUE r_self) {
if(int_coreloc_enable()) {
@@ -20,7 +20,9 @@ VALUE coreloc_enable(VALUE r_self) {
VALUE coreloc_pos(VALUE r_self) {
double lat, log;
- int_coreloc_get(&lat, &log);
+ if(!int_coreloc_get(&lat, &log)) {
+ return Qnil;
+ }
return rb_ary_new3(2, rb_float_new(lat),
rb_float_new(log));

0 comments on commit 255525a

Please sign in to comment.