Skip to content

Commit

Permalink
Added function for opening Google Maps App with directions
Browse files Browse the repository at this point in the history
  • Loading branch information
myell0w committed Mar 8, 2011
1 parent 60724f6 commit be29fe6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions MTLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
#import "MTLocationDefines.h"
#import "MTLocationManager.h"
#import "MTTouchesMovedGestureRecognizer.h"
#import "MTLocationFunctions.h"
8 changes: 8 additions & 0 deletions MTLocation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
392B1664132677BB00BF254A /* MTLocationFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 392B1662132677BB00BF254A /* MTLocationFunctions.h */; };
392B1665132677BB00BF254A /* MTLocationFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 392B1663132677BB00BF254A /* MTLocationFunctions.m */; };
39382D7A12E9B6400012007D /* MTLocateMeBarButtonItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 39382D7512E9B6400012007D /* MTLocateMeBarButtonItem.h */; };
39382D7B12E9B6400012007D /* MTLocateMeBarButtonItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 39382D7612E9B6400012007D /* MTLocateMeBarButtonItem.m */; };
39382D7C12E9B6400012007D /* MTLocateMeButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 39382D7712E9B6400012007D /* MTLocateMeButton.h */; };
Expand All @@ -27,6 +29,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
392B1662132677BB00BF254A /* MTLocationFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTLocationFunctions.h; sourceTree = "<group>"; };
392B1663132677BB00BF254A /* MTLocationFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTLocationFunctions.m; sourceTree = "<group>"; };
39382D7512E9B6400012007D /* MTLocateMeBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTLocateMeBarButtonItem.h; sourceTree = "<group>"; };
39382D7612E9B6400012007D /* MTLocateMeBarButtonItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTLocateMeBarButtonItem.m; sourceTree = "<group>"; };
39382D7712E9B6400012007D /* MTLocateMeButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTLocateMeButton.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -165,6 +169,8 @@
39382D7912E9B6400012007D /* MTLocationDefines.h */,
39645C0412FF585D008E8F9E /* MTTouchesMovedGestureRecognizer.h */,
39645C0512FF585D008E8F9E /* MTTouchesMovedGestureRecognizer.m */,
392B1662132677BB00BF254A /* MTLocationFunctions.h */,
392B1663132677BB00BF254A /* MTLocationFunctions.m */,
);
name = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -205,6 +211,7 @@
39645C0612FF585D008E8F9E /* MTTouchesMovedGestureRecognizer.h in Headers */,
39B0E06A131E58950057991D /* MKMapView+MTLocation.h in Headers */,
39781DB31323C6A80030FB3D /* MKAnnotationView+MTLocation.h in Headers */,
392B1664132677BB00BF254A /* MTLocationFunctions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -264,6 +271,7 @@
39645C0712FF585D008E8F9E /* MTTouchesMovedGestureRecognizer.m in Sources */,
39B0E06B131E58950057991D /* MKMapView+MTLocation.m in Sources */,
39781DB41323C6A80030FB3D /* MKAnnotationView+MTLocation.m in Sources */,
392B1665132677BB00BF254A /* MTLocationFunctions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
23 changes: 23 additions & 0 deletions MTLocationFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MTLocationFunctions.h
//
// Created by Matthias Tretter on 8.3.2011.
// Copyright (c) 2009-2011 Matthias Tretter, @myell0w. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

#define kMTDirectionModeCar @"kMTDirectionModeCar"
#define kMTDirectionModeWalking @"w"
#define kMTDirectionModePublicTransport @"r"


void MTOpenDirectionInGoogleMaps(CLLocationCoordinate2D startingPoint, CLLocationCoordinate2D endPoint, NSString *directionMode);
29 changes: 29 additions & 0 deletions MTLocationFunctions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// MTLocationFunctions.m
//
// Created by Matthias Tretter on 8.3.2011.
// Copyright (c) 2009-2011 Matthias Tretter, @myell0w. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


#import "MTLocationFunctions.h"



void MTOpenDirectionInGoogleMaps(CLLocationCoordinate2D startingPoint, CLLocationCoordinate2D endPoint, NSString *directionMode) {
NSString *googleMapsURL = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
startingPoint.latitude,startingPoint.longitude, endPoint.latitude, endPoint.longitude];

if (![directionMode isEqualToString:kMTDirectionModeCar]) {
googleMapsURL = [googleMapsURL stringByAppendingFormat:@"&dirflg=%@", directionMode];
}

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURL]];
}
14 changes: 13 additions & 1 deletion MTTouchesMovedGestureRecognizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ - (void)dealloc {
[super dealloc];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Began: %d", touches.count);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Touches: %d", touches.count);
NSLog(@"Moved: %d", touches.count);
if (touches.count == 1 && self.touchesMovedCallback) {
self.touchesMovedCallback(touches, event);
}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Ended: %d", touches.count);
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Cancelled: %d", touches.count);
}

- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer {
return NO;
}
Expand Down

0 comments on commit be29fe6

Please sign in to comment.