Permalink
Browse files

first commit.

  • Loading branch information...
kishikawakatsumi committed Aug 9, 2009
0 parents commit 2da80581cb3b18674971bf2d34b1494b88e34fa2
Showing with 3,840 additions and 0 deletions.
  1. +10 −0 .gitignore
  2. +50 −0 Classes/JSON.h
  3. +19 −0 Classes/MapDirectionsAppDelegate.h
  4. +43 −0 Classes/MapDirectionsAppDelegate.m
  5. +28 −0 Classes/MapDirectionsViewController.h
  6. +117 −0 Classes/MapDirectionsViewController.m
  7. +68 −0 Classes/NSObject+SBJSON.h
  8. +53 −0 Classes/NSObject+SBJSON.m
  9. +58 −0 Classes/NSString+SBJSON.h
  10. +55 −0 Classes/NSString+SBJSON.m
  11. +15 −0 Classes/RootViewController.h
  12. +213 −0 Classes/RootViewController.m
  13. +75 −0 Classes/SBJSON.h
  14. +212 −0 Classes/SBJSON.m
  15. +86 −0 Classes/SBJsonBase.h
  16. +78 −0 Classes/SBJsonBase.m
  17. +87 −0 Classes/SBJsonParser.h
  18. +475 −0 Classes/SBJsonParser.m
  19. +129 −0 Classes/SBJsonWriter.h
  20. +228 −0 Classes/SBJsonWriter.m
  21. +52 −0 Classes/UICGDirections.h
  22. +117 −0 Classes/UICGDirections.m
  23. +25 −0 Classes/UICGDirectionsOptions.h
  24. +13 −0 Classes/UICGDirectionsOptions.m
  25. +29 −0 Classes/UICGPolyline.h
  26. +54 −0 Classes/UICGPolyline.m
  27. +24 −0 Classes/UICGRoute.h
  28. +45 −0 Classes/UICGRoute.m
  29. +30 −0 Classes/UICGStep.h
  30. +52 −0 Classes/UICGStep.m
  31. +22 −0 Classes/UICGoogleMapsAPI.h
  32. +48 −0 Classes/UICGoogleMapsAPI.m
  33. +31 −0 Classes/UICRouteAnnotation.h
  34. +34 −0 Classes/UICRouteAnnotation.m
  35. +23 −0 Classes/UICRouteOverlayMapView.h
  36. +102 −0 Classes/UICRouteOverlayMapView.m
  37. +282 −0 MainWindow.xib
  38. +30 −0 MapDirections-Info.plist
  39. +382 −0 MapDirections.xcodeproj/project.pbxproj
  40. +14 −0 MapDirections_Prefix.pch
  41. +202 −0 RootViewController.xib
  42. +113 −0 api.html
  43. +17 −0 main.m
@@ -0,0 +1,10 @@
+build
+.DS_Store
+*.o
+*.ob
+*.pbxuser
+*.tmproj
+*.mode1*
+*.build
+*~.nib
+
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2009 Stig Brautaset. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of the author nor the names of its contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ @mainpage A strict JSON parser and generator for Objective-C
+
+ JSON (JavaScript Object Notation) is a lightweight data-interchange
+ format. This framework provides two apis for parsing and generating
+ JSON. One standard object-based and a higher level api consisting of
+ categories added to existing Objective-C classes.
+
+ Learn more on the http://code.google.com/p/json-framework project site.
+
+ This framework does its best to be as strict as possible, both in what it
+ accepts and what it generates. For example, it does not support trailing commas
+ in arrays or objects. Nor does it support embedded comments, or
+ anything else not in the JSON specification. This is considered a feature.
+
+*/
+
+#import "SBJSON.h"
+#import "NSObject+SBJSON.h"
+#import "NSString+SBJSON.h"
+
@@ -0,0 +1,19 @@
+//
+// MapDirectionsAppDelegate.h
+// MapDirections
+//
+// Created by KISHIKAWA Katsumi on 09/08/10.
+// Copyright KISHIKAWA Katsumi 2009. All rights reserved.
+//
+
+@interface MapDirectionsAppDelegate : NSObject <UIApplicationDelegate> {
+
+ UIWindow *window;
+ UINavigationController *navigationController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
+
+@end
+
@@ -0,0 +1,43 @@
+//
+// MapDirectionsAppDelegate.m
+// MapDirections
+//
+// Created by KISHIKAWA Katsumi on 09/08/10.
+// Copyright KISHIKAWA Katsumi 2009. All rights reserved.
+//
+
+#import "MapDirectionsAppDelegate.h"
+#import "RootViewController.h"
+
+
+@implementation MapDirectionsAppDelegate
+
+@synthesize window;
+@synthesize navigationController;
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (void)applicationDidFinishLaunching:(UIApplication *)application {
+
+ // Override point for customization after app launch
+
+ [window addSubview:[navigationController view]];
+ [window makeKeyAndVisible];
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ // Save data if appropriate
+}
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)dealloc {
+ [navigationController release];
+ [window release];
+ [super dealloc];
+}
+
+@end
+
@@ -0,0 +1,28 @@
+//
+// MapDirectionsViewController.h
+// MapDirections
+//
+// Created by KISHIKAWA Katsumi on 09/08/10.
+// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <MapKit/MapKit.h>
+#import "UICGDirections.h"
+
+@class UICRouteOverlayMapView;
+
+@interface MapDirectionsViewController : UIViewController<MKMapViewDelegate, UICGDirectionsDelegate> {
+ MKMapView *routeMapView;
+ UICRouteOverlayMapView *routeOverlayView;
+ UICGDirections *diretions;
+ NSString *startPoint;
+ NSString *endPoint;
+}
+
+@property (nonatomic, retain) NSString *startPoint;
+@property (nonatomic, retain) NSString *endPoint;
+
+- (void)update;
+
+@end
@@ -0,0 +1,117 @@
+//
+// MapDirectionsViewController.m
+// MapDirections
+//
+// Created by KISHIKAWA Katsumi on 09/08/10.
+// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
+//
+
+#import "MapDirectionsViewController.h"
+#import "UICRouteOverlayMapView.h"
+#import "UICGDirections.h"
+#import "UICRouteAnnotation.h"
+
+@implementation MapDirectionsViewController
+
+@synthesize startPoint;
+@synthesize endPoint;
+
+- (void)dealloc {
+ [routeOverlayView release];
+ [startPoint release];
+ [endPoint release];
+ [super dealloc];
+}
+
+- (void)loadView {
+ UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 416.0f)];
+ self.view = contentView;
+ [contentView release];
+ routeMapView = [[MKMapView alloc] initWithFrame:contentView.frame];
+ routeMapView.delegate = self;
+ [contentView addSubview:routeMapView];
+ [routeMapView release];
+
+ routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:routeMapView];
+
+ diretions = [UICGDirections sharedDirections];
+ diretions.delegate = self;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+}
+
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+ [self update];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+}
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+}
+
+- (void)update {
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
+ [diretions loadWithStartPoint:startPoint endPoint:endPoint options:nil];
+}
+
+- (void)directionsDidFinishInitialize:(UICGDirections *)directions {
+ [self update];
+}
+
+- (void)directionsDidUpdateDirections:(UICGDirections *)directions {
+ UICGPolyline *polyline = [directions polyline];
+ NSArray *routePoints = [polyline routePoints];
+ [routeOverlayView setRoutes:routePoints];
+
+ UICRouteAnnotation *startAnnotation = [[[UICRouteAnnotation alloc] initWithCoordinate:[[routePoints objectAtIndex:0] coordinate]
+ title:startPoint
+ annotationType:UICRouteAnnotationTypeStart] autorelease];
+
+ [routeMapView addAnnotation:startAnnotation];
+
+ UICRouteAnnotation *endAnnotation = [[[UICRouteAnnotation alloc] initWithCoordinate:[[routePoints lastObject] coordinate]
+ title:endPoint
+ annotationType:UICRouteAnnotationTypeEnd] autorelease];
+ [routeMapView addAnnotation:endAnnotation];
+
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+}
+
+- (void)directions:(UICGDirections *)directions didFailWithMessage:(NSString *)message {
+ NSLog(@"%@", message);
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+}
+
+#pragma mark <MKMapViewDelegate> Methods
+
+- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
+ routeOverlayView.hidden = YES;
+}
+
+- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
+ routeOverlayView.hidden = NO;
+ [routeOverlayView setNeedsDisplay];
+}
+
+- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
+ static NSString *identifier = @"Annotation";
+ MKPinAnnotationView *pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
+
+ if(!pinAnnotation) {
+ pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
+ }
+
+ pinAnnotation.pinColor = [(UICRouteAnnotation *)annotation annotationType] == UICRouteAnnotationTypeStart ? MKPinAnnotationColorGreen : MKPinAnnotationColorRed;
+ pinAnnotation.enabled = YES;
+ pinAnnotation.canShowCallout = YES;
+
+ return pinAnnotation;
+}
+
+@end
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2009 Stig Brautaset. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of the author nor the names of its contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+
+/**
+ @brief Adds JSON generation to Foundation classes
+
+ This is a category on NSObject that adds methods for returning JSON representations
+ of standard objects to the objects themselves. This means you can call the
+ -JSONRepresentation method on an NSArray object and it'll do what you want.
+ */
+@interface NSObject (NSObject_SBJSON)
+
+/**
+ @brief Returns a string containing the receiver encoded as a JSON fragment.
+
+ This method is added as a category on NSObject but is only actually
+ supported for the following objects:
+ @li NSDictionary
+ @li NSArray
+ @li NSString
+ @li NSNumber (also used for booleans)
+ @li NSNull
+
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
+ */
+- (NSString *)JSONFragment;
+
+/**
+ @brief Returns a string containing the receiver encoded in JSON.
+
+ This method is added as a category on NSObject but is only actually
+ supported for the following objects:
+ @li NSDictionary
+ @li NSArray
+ */
+- (NSString *)JSONRepresentation;
+
+@end
+
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2009 Stig Brautaset. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of the author nor the names of its contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "NSObject+SBJSON.h"
+#import "SBJsonWriter.h"
+
+@implementation NSObject (NSObject_SBJSON)
+
+- (NSString *)JSONFragment {
+ SBJsonWriter *jsonWriter = [SBJsonWriter new];
+ NSString *json = [jsonWriter stringWithFragment:self];
+ if (json)
+ NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]);
+ [jsonWriter release];
+ return json;
+}
+
+- (NSString *)JSONRepresentation {
+ SBJsonWriter *jsonWriter = [SBJsonWriter new];
+ NSString *json = [jsonWriter stringWithObject:self];
+ if (json)
+ NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]);
+ [jsonWriter release];
+ return json;
+}
+
+@end
Oops, something went wrong.

0 comments on commit 2da8058

Please sign in to comment.