/[zanavi_public1]/navit/navit/vehicle/iphone/corelocation.m
ZANavi

Contents of /navit/navit/vehicle/iphone/corelocation.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File size: 3257 byte(s)
import files
1 /**
2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #define VEHICLE_IPHONE_OBJC
21 #import "corelocation.h"
22
23 #import <Foundation/Foundation.h>
24 #import <UIKit/UIKit.h>
25
26 /* global location structure */
27 corelocation *locationcontroller = NULL;
28
29 /** C update procedure */
30 void corelocation_update(double lat, double lng, double dir, double spd, char * str_time, double radius) {
31 FT_LOCATION_CB pf_cb = locationcontroller->pf_cb;
32 void * pv_arg = locationcontroller->pv_arg;
33 if(pf_cb) pf_cb(pv_arg, lat, lng, dir, spd, str_time, radius);
34 }
35
36 /** C init procedure */
37 void corelocation_init(void * pv_arg, FT_LOCATION_CB pf_cb) {
38 locationcontroller = [[corelocation alloc] init];
39
40 /** Save callbacks */
41 locationcontroller->pv_arg = pv_arg;
42 locationcontroller->pf_cb = pf_cb;
43
44 /** Start location process */
45 [locationcontroller.locationManager startUpdatingLocation];
46 }
47
48 /** C exit procedure */
49 void corelocation_exit(void) {
50 [locationcontroller dealloc];
51 }
52
53 /** Core location implementation */
54 @implementation corelocation
55
56 @synthesize locationManager;
57 @synthesize dateFormatter;
58 @synthesize eventDate;
59 @synthesize pv_arg;
60 @synthesize pf_cb;
61
62 /** Init corelocation */
63 - (id) init {
64 self = [super init];
65 if (self != nil) {
66 self.locationManager = [[[CLLocationManager alloc] init] autorelease];
67 self.locationManager.distanceFilter = kCLDistanceFilterNone;
68 self.locationManager.delegate = self; // send loc updates to myself
69 self.pf_cb = NULL;
70 self.pv_arg = NULL;
71 self.eventDate = [NSDate date];
72 self.dateFormatter = [[NSDateFormatter alloc] init];
73 [self.dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
74 }
75 return self;
76 }
77
78 /** New Data EVENT */
79 - (void)locationManager:(CLLocationManager *)manager
80 didUpdateToLocation:(CLLocation *)newLocation
81 fromLocation:(CLLocation *)oldLocation
82 {
83 NSLog(@"New Location: %@", [newLocation description]);
84 NSString *newDateString = [self.dateFormatter stringFromDate:newLocation.timestamp];
85 const char* cString = [newDateString cStringUsingEncoding:NSASCIIStringEncoding];
86
87 if(self.pf_cb) {
88 self.pf_cb(
89 self.pv_arg,
90 (double)newLocation.coordinate.latitude,
91 (double) newLocation.coordinate.longitude,
92 (double) newLocation.course,
93 (double) newLocation.speed,
94 cString,
95 (double) newLocation.horizontalAccuracy
96 );
97 }
98 }
99
100 /** Error EVENT */
101 - (void)locationManager:(CLLocationManager *)manager
102 didFailWithError:(NSError *)error
103 {
104 NSLog(@"Error: %@", [error description]);
105 }
106
107 /** Destructor */
108 - (void)dealloc {
109 [self.locationManager release];
110 [super dealloc];
111 }
112
113 @end
114

   
Visit the ZANavi Wiki