From 45fea885436faf70ebe589447322e576c7697199 Mon Sep 17 00:00:00 2001 From: Dominik Krejcik Date: Mon, 30 Jun 2014 21:08:23 +0100 Subject: [PATCH 1/5] Fix Google Maps URL to work with newest version of the URL --- CMMapLauncher/CMMapLauncher.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMMapLauncher/CMMapLauncher.m b/CMMapLauncher/CMMapLauncher.m index ee53704..cbb6da1 100644 --- a/CMMapLauncher/CMMapLauncher.m +++ b/CMMapLauncher/CMMapLauncher.m @@ -79,7 +79,7 @@ + (NSString *)googleMapsStringForMapPoint:(CMMapPoint *)mapPoint { } if (mapPoint.name) { - return [NSString stringWithFormat:@"%f,%f+(%@)", mapPoint.coordinate.latitude, mapPoint.coordinate.longitude, [CMMapLauncher urlEncode:mapPoint.name]]; + return [NSString stringWithFormat:@"%f,%f", mapPoint.coordinate.latitude, mapPoint.coordinate.longitude]; } return [NSString stringWithFormat:@"%f,%f", mapPoint.coordinate.latitude, mapPoint.coordinate.longitude]; From 56480cbba46d2f41e247f15ebf408d33dda22f86 Mon Sep 17 00:00:00 2001 From: Dominik Krejcik Date: Sat, 2 Aug 2014 13:39:41 +0100 Subject: [PATCH 2/5] Default Apple maps to walking instead of driving --- CMMapLauncher/CMMapLauncher.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMMapLauncher/CMMapLauncher.m b/CMMapLauncher/CMMapLauncher.m index cbb6da1..2f99414 100644 --- a/CMMapLauncher/CMMapLauncher.m +++ b/CMMapLauncher/CMMapLauncher.m @@ -113,7 +113,7 @@ + (BOOL)launchMapApp:(CMMapApp)mapApp // Check for iOS 6 Class mapItemClass = [MKMapItem class]; if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { - NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}; + NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking}; return [MKMapItem openMapsWithItems:@[start.MKMapItem, end.MKMapItem] launchOptions:launchOptions]; } else { // iOS 5 NSString *url = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@", From aa684b018bead79d384c261eb87257a40bee6a59 Mon Sep 17 00:00:00 2001 From: Dominik Krejcik Date: Fri, 14 Nov 2014 20:03:02 +0000 Subject: [PATCH 3/5] Add Uber as an option --- CMMapLauncher/CMMapLauncher.m | 53 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/CMMapLauncher/CMMapLauncher.m b/CMMapLauncher/CMMapLauncher.m index cbb6da1..c840f2b 100644 --- a/CMMapLauncher/CMMapLauncher.m +++ b/CMMapLauncher/CMMapLauncher.m @@ -36,22 +36,25 @@ + (NSString *)urlPrefixForMapApp:(CMMapApp)mapApp { switch (mapApp) { case CMMapAppCitymapper: return @"citymapper://"; - + case CMMapAppGoogleMaps: return @"comgooglemaps://"; - + case CMMapAppNavigon: return @"navigon://"; - + case CMMapAppTheTransitApp: return @"transit://"; - + case CMMapAppWaze: return @"waze://"; - + case CMMapAppYandex: return @"yandexnavi://"; - + + case CMMapAppUber: + return @"uber://"; + default: return nil; } @@ -61,11 +64,11 @@ + (NSString *)urlEncode:(NSString *)queryParam { // Encode all the reserved characters, per RFC 3986 // () NSString *newString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)queryParam, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); - + if (newString) { return newString; } - + return @""; } @@ -73,28 +76,28 @@ + (NSString *)googleMapsStringForMapPoint:(CMMapPoint *)mapPoint { if (!mapPoint) { return @""; } - + if (mapPoint.isCurrentLocation && mapPoint.coordinate.latitude == 0.0 && mapPoint.coordinate.longitude == 0.0) { return @""; } - + if (mapPoint.name) { return [NSString stringWithFormat:@"%f,%f", mapPoint.coordinate.latitude, mapPoint.coordinate.longitude]; } - + return [NSString stringWithFormat:@"%f,%f", mapPoint.coordinate.latitude, mapPoint.coordinate.longitude]; } + (BOOL)isMapAppInstalled:(CMMapApp)mapApp { - if (mapApp == CMMapAppAppleMaps) { + if (mapApp == CMMapAppAppleMaps || mapApp == CMMapAppUber) { return YES; } - + NSString *urlPrefix = [CMMapLauncher urlPrefixForMapApp:mapApp]; if (!urlPrefix) { return NO; } - + return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlPrefix]]; } @@ -108,12 +111,12 @@ + (BOOL)launchMapApp:(CMMapApp)mapApp if (![CMMapLauncher isMapAppInstalled:mapApp]) { return NO; } - + if (mapApp == CMMapAppAppleMaps) { // Check for iOS 6 Class mapItemClass = [MKMapItem class]; if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { - NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving}; + NSDictionary *launchOptions = @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking}; return [MKMapItem openMapsWithItems:@[start.MKMapItem, end.MKMapItem] launchOptions:launchOptions]; } else { // iOS 5 NSString *url = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@", @@ -152,7 +155,7 @@ + (BOOL)launchMapApp:(CMMapApp)mapApp return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; } else if (mapApp == CMMapAppTheTransitApp) { // http://thetransitapp.com/developers - + NSMutableArray *params = [NSMutableArray arrayWithCapacity:2]; if (start && !start.isCurrentLocation) { [params addObject:[NSString stringWithFormat:@"from=%f,%f", start.coordinate.latitude, start.coordinate.longitude]]; @@ -164,7 +167,7 @@ + (BOOL)launchMapApp:(CMMapApp)mapApp return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; } else if (mapApp == CMMapAppNavigon) { // http://www.navigon.com/portal/common/faq/files/NAVIGON_AppInteract.pdf - + NSString *name = @"Destination"; // Doc doesn't say whether name can be omitted if (end.name) { name = end.name; @@ -182,8 +185,14 @@ + (BOOL)launchMapApp:(CMMapApp)mapApp url = [NSString stringWithFormat:@"yandexnavi://build_route_on_map?lat_to=%f&lon_to=%f&lat_from=%f&lon_from=%f", end.coordinate.latitude, end.coordinate.longitude, start.coordinate.latitude, start.coordinate.longitude]; } return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; + } else if (mapApp == CMMapAppUber) { + NSString *url = nil; + if (start.isCurrentLocation) { + url = [NSString stringWithFormat:@"uber://?action=setPickup&pickup=my_location&dropoff[latitude]=%f&dropoff[longitude]=%f", end.coordinate.latitude, end.coordinate.longitude]; + } else { + url = [NSString stringWithFormat:@"uber://?action=setPickup&pickup[latitude]=%f&pickup[longitude]=%f&dropoff[latitude]=%f&dropoff[longitude]=%f", start.coordinate.latitude, start.coordinate.longitude, end.coordinate.latitude, end.coordinate.longitude]; + } } - return NO; } @@ -237,7 +246,7 @@ - (NSString *)name { if (_isCurrentLocation) { return @"Current Location"; } - + return _name; } @@ -245,9 +254,9 @@ - (MKMapItem *)MKMapItem { if (_isCurrentLocation) { return [MKMapItem mapItemForCurrentLocation]; } - + MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:_coordinate addressDictionary:nil]; - + MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark]; item.name = self.name; return item; From ea5c729d501e83503974715314f1b7a50f38f51a Mon Sep 17 00:00:00 2001 From: Dominik Krejcik Date: Sun, 16 Nov 2014 21:46:54 +0000 Subject: [PATCH 4/5] Fix Uber --- CMMapLauncher/CMMapLauncher.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMMapLauncher/CMMapLauncher.m b/CMMapLauncher/CMMapLauncher.m index c840f2b..0b8f783 100644 --- a/CMMapLauncher/CMMapLauncher.m +++ b/CMMapLauncher/CMMapLauncher.m @@ -188,10 +188,11 @@ + (BOOL)launchMapApp:(CMMapApp)mapApp } else if (mapApp == CMMapAppUber) { NSString *url = nil; if (start.isCurrentLocation) { - url = [NSString stringWithFormat:@"uber://?action=setPickup&pickup=my_location&dropoff[latitude]=%f&dropoff[longitude]=%f", end.coordinate.latitude, end.coordinate.longitude]; + url = [NSString stringWithFormat:@"uber://?action=setPickup&pickup=my_location&dropoff[latitude]=%f&dropoff[longitude]=%f&dropoff[nickname]=%@", end.coordinate.latitude, end.coordinate.longitude, [end.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; } else { - url = [NSString stringWithFormat:@"uber://?action=setPickup&pickup[latitude]=%f&pickup[longitude]=%f&dropoff[latitude]=%f&dropoff[longitude]=%f", start.coordinate.latitude, start.coordinate.longitude, end.coordinate.latitude, end.coordinate.longitude]; + url = [NSString stringWithFormat:@"uber://?action=setPickup&pickup[latitude]=%f&pickup[longitude]=%f&dropoff[latitude]=%f&dropoff[longitude]=%f&dropoff[nickname]=%@", start.coordinate.latitude, start.coordinate.longitude, end.coordinate.latitude, end.coordinate.longitude, [end.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; } + return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; } return NO; } From c71fcaa3bbb8f9793b40dab178819ef5ea3e7906 Mon Sep 17 00:00:00 2001 From: Dominik Krejcik Date: Mon, 2 Feb 2015 17:38:14 +0000 Subject: [PATCH 5/5] Uber isn't always installed --- CMMapLauncher/CMMapLauncher.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMMapLauncher/CMMapLauncher.m b/CMMapLauncher/CMMapLauncher.m index 0b8f783..97245f9 100644 --- a/CMMapLauncher/CMMapLauncher.m +++ b/CMMapLauncher/CMMapLauncher.m @@ -89,7 +89,7 @@ + (NSString *)googleMapsStringForMapPoint:(CMMapPoint *)mapPoint { } + (BOOL)isMapAppInstalled:(CMMapApp)mapApp { - if (mapApp == CMMapAppAppleMaps || mapApp == CMMapAppUber) { + if (mapApp == CMMapAppAppleMaps) { return YES; }