vehicle_gpsd=yes; vehicle_gpsd_reason=default
vehicle_gypsy=yes; vehicle_gypsy_reason=default
vehicle_wince=no; vehicle_wince_reason=default
+vehicle_iphone=no; vehicle_iphone_reason=default
vehicle_android=no; vehicle_android_reason=default
graphics_android=no; graphics_android_reason=default
AC_USE_SYSTEM_EXTENSIONS
+AC_PROG_OBJC
AC_PROG_CC
AC_PROG_OBJC
if eval "test x`uname` = xDarwin"; then
# wince
AC_ARG_ENABLE(vehicle-wince, [ --disable-vehicle-wince disable vehicle type wince], vehicle_wince=$enableval;vehicle_wince_reason="configure parameter")
AM_CONDITIONAL(VEHICLE_WINCE, test "x${vehicle_wince}" = "xyes")
-
+# iphone
+AC_ARG_ENABLE(vehicle-iphone, [ --disable-vehicle-iphone disable vehicle type iphone], vehicle_iphone=$enableval;vehicle_iphone_reason="configure parameter")
+AM_CONDITIONAL(VEHICLE_IPHONE, test "x${vehicle_iphone}" = "xyes")
+if test "x${vehicle_iphone}" = "xyes"
+then
+ IPHONE_LIBS=-Wl,-framework,CoreLocation
+fi
+AC_SUBST(IPHONE_CFLAGS)
+AC_SUBST(IPHONE_LIBS)
NAVIT_CFLAGS="$NAVIT_CFLAGS $GLIB_CFLAGS $GMODULE_CFLAGS"
NAVIT_LIBS="$NAVIT_LIBS $GLIB_LIBS $GMODULE_LIBS $LIBINTL"
AC_SUBST(NAVIT_CFLAGS)
navit/vehicle/gypsy/Makefile
navit/vehicle/demo/Makefile
navit/vehicle/wince/Makefile
+navit/vehicle/iphone/Makefile
navit/xpm/Makefile
navit/maps/Makefile
intl/Makefile
echo " gpsd: $vehicle_gpsd ($vehicle_gpsd_reason)"
echo " gypsy: $vehicle_gypsy ($vehicle_gypsy_reason)"
echo " wince: $vehicle_wince ($vehicle_wince_reason)"
+echo " iphone: $vehicle_iphone ($vehicle_iphone_reason)"
if test "x${gtk2_pkgconfig}" != "xyes" -a "x${gui_win32}" != "xyes" -a "x${gui_internal}" != "xyes"
then
ATTR(position_speed)
ATTR(position_direction)
ATTR(position_hdop)
+ATTR(position_radius)
ATTR2(0x0005ffff,type_double_end)
ATTR2(0x00060000,type_coord_geo_begin)
ATTR(position_coord_geo)
vehicle_log_gpx(struct vehicle *this_, struct log *log)
{
struct attr pos_attr;
+ struct attr radius_attr;
struct attr time_attr;
struct attr *profile_attr;
+ struct attr speed_attr;
+ struct attr course_attr;
+ char buffer[256];
+ char tbuf[256];
char *timep;
+ double zero = 0.0f;
int free=0;
if (!this_->meth.position_attr_get)
return;
if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
return;
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_radius, &radius_attr))
+ radius_attr.u.numd = &zero;
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_speed, &speed_attr))
+ speed_attr.u.numd = &zero;
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_direction, &course_attr))
+ course_attr.u.numd = &zero;
if (!this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &time_attr)) {
timep = current_to_iso8601();
free=1;
log_printf(log,
"<trkpt lat=\"%f\" lon=\"%f\">\n"
"\t<time>%s</time>\n"
- "\t<extensions><navit:profilename>%s</navit:profilename></extensions>\n"
+ "\t<course>%.1f</course>\n"
+ "\t<speed>%.2f</speed>\n"
+ "\t<extensions>"
+ "\t\t<radius>%.2f</radius>\n"
+ "\t\t<navit:profilename>%s</navit:profilename>\n"
+ "\t</extensions>\n"
"</trkpt>\n",
pos_attr.u.coord_geo->lat,
pos_attr.u.coord_geo->lng,
timep,
+ (*course_attr.u.numd),
+ (*speed_attr.u.numd),
+ (*radius_attr.u.numd),
profile_attr->u.str
);
if VEHICLE_ANDROID
SUBDIRS += android
endif
+if VEHICLE_IPHONE
+ SUBDIRS += iphone
+endif
if VEHICLE_DEMO
SUBDIRS += demo
endif
--- /dev/null
+include $(top_srcdir)/Makefile.inc
+AM_CPPFLAGS = @NAVIT_CFLAGS@ -I$(top_srcdir)/navit -DMODULE=vehicle_iphone
+modulevehicle_LTLIBRARIES = libvehicle_iphone.la
+libvehicle_iphone_la_SOURCES = vehicle_iphone.c corelocation.m
+libvehicle_iphone_la_LDFLAGS = -module -Wl,-framework,CoreLocation
+libvehicle_iphone_la_LIBADD = @IPHONE_LIBS@
--- /dev/null
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef VEHICLE_IPHONE_CORELOCATION_H
+#define VEHICLE_IPHONE_CORELOCATION_H
+
+typedef void(*FT_LOCATION_CB)(void *, double , double , double , double, char *, double);
+void corelocation_update(double lat,
+ double lng,
+ double dir,
+ double spd,
+ char * time,
+ double radius);
+void corelocation_init(void * pv_arg, FT_LOCATION_CB pf_cb);
+void corelocation_exit(void);
+
+#ifdef VEHICLE_IPHONE_OBJC
+#import <CoreLocation/CoreLocation.h>
+
+
+@interface corelocation : NSObject <CLLocationManagerDelegate> {
+ CLLocationManager *locationManager;
+ NSDateFormatter *dateFormatter;
+ NSDate* eventDate;
+@public
+ FT_LOCATION_CB pf_cb;
+ void * pv_arg;
+}
+
+@property (nonatomic, retain) CLLocationManager *locationManager;
+@property (nonatomic, retain) NSDateFormatter *dateFormatter;
+@property (nonatomic, retain) NSDate* eventDate;
+@property (nonatomic) int first;
+@property (nonatomic) void * pv_arg;
+@property (nonatomic) FT_LOCATION_CB pf_cb;
+
+- (void)locationManager:(CLLocationManager *)manager
+ didUpdateToLocation:(CLLocation *)newLocation
+ fromLocation:(CLLocation *)oldLocation;
+
+- (void)locationManager:(CLLocationManager *)manager
+ didFailWithError:(NSError *)error;
+
+@end
+
+#endif
+#endif
--- /dev/null
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#define VEHICLE_IPHONE_OBJC
+#import "corelocation.h"
+
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+/* global location structure */
+corelocation *locationcontroller = NULL;
+
+/** C update procedure */
+void corelocation_update(double lat, double lng, double dir, double spd, char * str_time, double radius) {
+ FT_LOCATION_CB pf_cb = locationcontroller->pf_cb;
+ void * pv_arg = locationcontroller->pv_arg;
+ if(pf_cb) pf_cb(pv_arg, lat, lng, dir, spd, str_time, radius);
+}
+
+/** C init procedure */
+void corelocation_init(void * pv_arg, FT_LOCATION_CB pf_cb) {
+ locationcontroller = [[corelocation alloc] init];
+
+ /** Save callbacks */
+ locationcontroller->pv_arg = pv_arg;
+ locationcontroller->pf_cb = pf_cb;
+
+ /** Start location process */
+ [locationcontroller.locationManager startUpdatingLocation];
+}
+
+/** C exit procedure */
+void corelocation_exit(void) {
+ [locationcontroller dealloc];
+}
+
+/** Core location implementation */
+@implementation corelocation
+
+@synthesize locationManager;
+@synthesize dateFormatter;
+@synthesize eventDate;
+@synthesize pv_arg;
+@synthesize pf_cb;
+
+/** Init corelocation */
+- (id) init {
+ self = [super init];
+ if (self != nil) {
+ self.locationManager = [[[CLLocationManager alloc] init] autorelease];
+ self.locationManager.distanceFilter = kCLDistanceFilterNone;
+ self.locationManager.delegate = self; // send loc updates to myself
+ self.pf_cb = NULL;
+ self.pv_arg = NULL;
+ self.eventDate = [NSDate date];
+ self.dateFormatter = [[NSDateFormatter alloc] init];
+ [self.dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
+ }
+ return self;
+}
+
+/** New Data EVENT */
+- (void)locationManager:(CLLocationManager *)manager
+didUpdateToLocation:(CLLocation *)newLocation
+fromLocation:(CLLocation *)oldLocation
+{
+ NSLog(@"New Location: %@", [newLocation description]);
+ NSString *newDateString = [self.dateFormatter stringFromDate:newLocation.timestamp];
+ const char* cString = [newDateString cStringUsingEncoding:NSASCIIStringEncoding];
+
+ if(self.pf_cb) {
+ self.pf_cb(
+ self.pv_arg,
+ (double)newLocation.coordinate.latitude,
+ (double) newLocation.coordinate.longitude,
+ (double) newLocation.course,
+ (double) newLocation.speed,
+ cString,
+ (double) newLocation.horizontalAccuracy
+ );
+ }
+}
+
+/** Error EVENT */
+- (void)locationManager:(CLLocationManager *)manager
+didFailWithError:(NSError *)error
+{
+ NSLog(@"Error: %@", [error description]);
+}
+
+/** Destructor */
+- (void)dealloc {
+ [self.locationManager release];
+ [super dealloc];
+}
+
+@end
+
--- /dev/null
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+#include <string.h>
+#include "config.h"
+#include "debug.h"
+#include "coord.h"
+#include "item.h"
+#include "navit.h"
+#include "map.h"
+#include "route.h"
+#include "callback.h"
+#include "transform.h"
+#include "plugin.h"
+#include "vehicle.h"
+#include "event.h"
+#include "corelocation.h"
+
+struct vehicle_priv {
+ int interval;
+ int position_set;
+ struct callback_list *cbl;
+ struct navit *navit;
+ struct coord_geo geo;
+ struct coord last;
+ double config_speed;
+ double speed;
+ double direction;
+ double radius;
+ struct callback *timer_callback;
+ struct event_timeout *timer;
+ char str_time[200];
+};
+
+static void
+vehicle_iphone_destroy(struct vehicle_priv *priv)
+{
+ corelocation_exit();
+ g_free(priv);
+}
+
+static int
+vehicle_iphone_position_attr_get(struct vehicle_priv *priv,
+ enum attr_type type, struct attr *attr)
+{
+ switch (type) {
+ case attr_position_speed:
+ attr->u.numd = &priv->speed;
+ break;
+ case attr_position_direction:
+ attr->u.numd = &priv->direction;
+ break;
+ case attr_position_coord_geo:
+ attr->u.coord_geo = &priv->geo;
+ break;
+ case attr_position_time_iso8601:
+ attr->u.str = priv->str_time;
+ break;
+ case attr_position_radius:
+ attr->u.numd = &priv->radius;
+ break;
+ case attr_position_nmea:
+ return 0;
+ default:
+ return 0;
+ }
+ attr->type = type;
+ return 1;
+}
+
+static int
+vehicle_iphone_set_attr(struct vehicle_priv *priv, struct attr *attr,
+ struct attr **attrs)
+{
+ if (attr->type == attr_navit) {
+ priv->navit = attr->u.navit;
+ return 1;
+ }
+ return 0;
+}
+
+struct vehicle_methods vehicle_iphone_methods = {
+ vehicle_iphone_destroy,
+ vehicle_iphone_position_attr_get,
+ vehicle_iphone_set_attr,
+};
+
+void
+vehicle_iphone_update(void *arg,
+ double lat,
+ double lng,
+ double dir,
+ double spd,
+ char * str_time,
+ double radius
+ )
+{
+ struct vehicle_priv * priv = arg;
+ priv->geo.lat = lat;
+ priv->geo.lng = lng;
+ if(dir > 0) priv->direction = dir;
+ if(spd > 0) priv->speed = spd*3.6;
+ strcpy(priv->str_time, str_time);
+ priv->radius = radius;
+
+ dbg(0,"position_get lat:%f lng:%f (spd:%f dir:%f time:%s)\n", priv->geo.lat, priv->geo.lng, priv->speed, priv->direction, priv->str_time);
+ callback_list_call_0(priv->cbl);
+}
+
+
+
+static struct vehicle_priv *
+vehicle_iphone_new(struct vehicle_methods
+ *meth, struct callback_list
+ *cbl, struct attr **attrs)
+{
+ struct vehicle_priv *ret;
+ struct attr *interval,*speed,*position_coord_geo;
+
+ dbg(1, "enter\n");
+ ret = g_new0(struct vehicle_priv, 1);
+ ret->cbl = cbl;
+ ret->interval=1000;
+ ret->config_speed=40;
+ if ((speed=attr_search(attrs, NULL, attr_speed))) {
+ ret->config_speed=speed->u.num;
+ }
+ if ((interval=attr_search(attrs, NULL, attr_interval)))
+ ret->interval=interval->u.num;
+ if ((position_coord_geo=attr_search(attrs, NULL, attr_position_coord_geo))) {
+ ret->geo=*(position_coord_geo->u.coord_geo);
+ ret->position_set=1;
+ dbg(0,"position_set %f %f\n", ret->geo.lat, ret->geo.lng);
+ }
+ *meth = vehicle_iphone_methods;
+ ret->str_time[0] = '\0';
+
+ /** Initialize corelocation */
+ corelocation_init(ret, vehicle_iphone_update);
+
+ return ret;
+}
+
+void
+plugin_init(void)
+{
+ dbg(1, "enter\n");
+ plugin_register_vehicle_type("iphone", vehicle_iphone_new);
+}