Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 4709addc443cfa3a81758dcdffa5caccc70bd2a3 kellyp committed Sep 25, 2009
Showing 1,038 changed files with 275,356 additions and 0 deletions.
@@ -0,0 +1,94 @@
+/*
+ * AppController.j
+ * corelocation
+ *
+ * Created by Yo Mama on September 23, 2009.
+ * Copyright 2009, Your Company All rights reserved.
+ */
+
+@import <Foundation/CPObject.j>
+@import "CLLocationManager.j"
+
+@implementation AppController : CPObject
+{
+ CPTextField label;
+ CPView contentView;
+ CLLocationManager locationManager;
+
+}
+
+- (void)applicationDidFinishLaunching:(CPNotification)aNotification
+{
+ var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
+
+ contentView = [theWindow contentView];
+
+ label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
+
+ [label setStringValue:@"Hello CoreLocation!"];
+ [label setFont:[CPFont boldSystemFontOfSize:24.0]];
+
+ [label sizeToFit];
+
+ [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
+ [label setCenter:[contentView center]];
+
+ [contentView addSubview:label];
+
+ [theWindow orderFront:self];
+
+ locationManager = [[CLLocationManager alloc] init];
+ if(![locationManager locationServicesEnabled]){
+ [self _setLabelValue:@"CoreLocation not supported"];
+ }else{
+ [self _setLabelValue:@"CoreLocation supported"];
+ }
+ [locationManager setDelegate: self];
+ [locationManager startUpdatingLocation];
+ // Uncomment the following line to turn on the standard menu bar.
+ //[CPMenu setMenuBarVisible:YES];
+}
+
+
+-(void) _setLabelValue: (CPString) aString
+{
+ [label setStringValue: aString];
+ [label sizeToFit];
+
+ [label setCenter:[contentView center]];
+
+}
+
+//CLLocationManagerDelegate
+- (void)locationManager:(CLLocationManager)manager didFailWithError:(CPError)error
+{
+/*
+ CPLogConsole(manager);
+ CPLogConsole(error);
+*/
+}
+
+- (void)locationManager:(CLLocationManager)manager didUpdateHeading:(CLHeading)newHeading
+{
+/*
+ CPLogConsole(manager);
+ CPLogConsole(newHeading);
+*/
+}
+
+- (void)locationManager:(CLLocationManager)manager didUpdateToLocation:(CLLocation)newLocation fromLocation:(CLLocation)oldLocation
+{
+ [self _setLabelValue: [newLocation description]];
+
+ console.warn("stopUpdatingLocation");
+ [locationManager stopUpdatingLocation];
+
+}
+
+- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager)manager
+{
+/* CPLogConsole(manager); */
+}
+//CLLocationManagerDelegate
+
+@end
@@ -0,0 +1,69 @@
+
+
+/*
+ * CLHeading.j
+ * CoreLocation
+ *
+ * Created by Kelly Plummer.
+ * Copyright 2009, Kelly Plummer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+ @import <Foundation/CPObject.j>
+
+ /*!
+ @ingroup corelocation
+ @code CLHeading
+
+ */
+ @implementation CLHeading : CPObject
+ {
+ double _magneticHeading @accessors(getter=magneticHeading);
+ double _trueHeading @accessors(getter=trueHeading);
+ double _headingAccuracy @accessors(getter=headingAccuracy);
+ double _timestamp @accessors(getter=timestamp);
+ double _x @accessors(getter=x);
+ double _y @accessors(getter=y);
+ double _z @accessors(getter=z);
+
+ }
+
+
+ - (CLHeading) _initWithMagneticHeading: (double) mHeading trueHeading: (double) tHeading timestamp: (CPDate) timestamp
+ {
+ self = [super init];
+ if(self){
+ _magneticHeading = mHeading;
+ _trueHeading = tHeading;
+ _timestamp = [[CPDate alloc] initWithTimeIntervalSince1970: timestamp / 1000];
+ }
+
+ return self;
+ }
+
+
+ /*!
+ A string of the form ÒmagneticHeading <magnetic> trueHeading <heading> accuracy <accuracy> x <x> y <y> z <z> @ <date-time>Ó
+ where <magnetic>, <heading>, <accuracy>, <x>, <y>, and <z> are formatted floating point numbers
+ and <date-time> is a formatted date string that includes date, time, and time zone information.
+ */
+ - (CPString)description
+ {
+
+ }
+
+ @end
@@ -0,0 +1,120 @@
+
+
+/*
+ * CLLocation.j
+ * CoreLocation
+ *
+ * Created by Kelly Plummer.
+ * Copyright 2009, Kelly Plummer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ @import <Foundation/CPObject.j>
+
+ /*!
+ @ingroup corelocation
+ @code CLocation
+
+ */
+ @implementation CLLocation : CPObject
+ {
+ CLLocationCoordinate2D _coordinate @accessors(getter=coordinate);
+ double _altitude @accessors(getter=altitude);
+
+ double _horizontalAccuracy @accessors(getter=horizontalAccuracy);
+ double _verticalAccuracy @accessors(getter=verticalAccuracy);
+ CPDate _timestamp @accessors(getter=timeStamp);
+
+ double _speed @accessors(getter=speed);
+ double _course @accessors(getter=course);
+
+ }
+
+
+ - (id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
+ {
+ self = [super init];
+ if(self){
+ _coordinate = new CLLocationCoordinate2D();
+ _coordinate.latitude = latitude;
+ _coordinate.longitude = longitude;
+ }
+ return self;
+ }
+
+ - (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate altitude:(CLLocationDistance)altitude horizontalAccuracy:(CLLocationAccuracy)hAccuracy verticalAccuracy:(CLLocationAccuracy)vAccuracy timestamp:(CPDate)timestamp
+ {
+ self = [super init];
+ if(self){
+ _coordinate = coordinate;
+ _altitude = altitude;
+ _horizontalAccuracy = hAccuracy;
+ _verticalAccuracy = vAccuracy;
+ _timestamp = [[CPDate alloc] initWithTimeIntervalSince1970: timestamp / 1000];
+ }
+
+ return self;
+ }
+
+
+- (CLLocationDistance)getDistanceFrom:(CLLocation)location
+{
+ var lat1 = _coordinate.latitude;
+ var lon1 = _coordinate.longitude;
+ var lat2 = [location coordinate].latitude;
+ var lon2 = [location coordinate].longitude;
+
+
+ if (ABS(lat1) > 90 || ABS(lat2) > 90){
+ return -1;
+ }
+ lat1 = ABS([self _toRadians: lat1]);
+ lon1 = ABS([self _toRadians: lon1]);
+ lat2 = ABS([self _toRadians: lat2]);
+ lon2 = ABS([self _toRadians: lon2]);
+
+ var d = 2 * Math.asin(Math.sqrt((Math.pow(Math.sin((lat1 - lat2) / 2) , 2)) + Math.pow(Math.cos(lat1) * Math.cos(lat2) * (Math.sin((lon1 - lon2) / 2)) , 2)));
+ //convert from nautical miles to meters
+ d = d * 1852;
+ return d * 180*60/Math.PI ;
+
+}
+
+- (double) _toRadians: (double) degrees
+{
+ return degrees * PI / 180
+}
+
+- (CPString) description
+{
+ //A string of the form Ò<<latitude>, <longitude>> +/- <accuracy>m (speed <speed> kph / heading <heading>) @ <date-time>Ó,
+ //where <latitude>, <longitude>, <accuracy>, <speed>, and <heading> are formatted floating point numbers
+ //and <date-time> is a formatted date string that includes date, time, and time zone information.
+
+ return _coordinate.latitude + ", " + _coordinate.longitude + " +/- " + _horizontalAccuracy + "m " + " @ " + [_timestamp description];
+}
+
+@end
+
+
+
+ CLLocationCoordinate2D = function (lat, lon) {
+ this.latitude = lat;
+ this.longitude = lon;
+ }
+
+
+
Oops, something went wrong.

0 comments on commit 4709add

Please sign in to comment.