Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Mar 3, 2013
1 parent bc7b9a8 commit bed9ee8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .theos/packages/ws.hbang.mapsopener-1.1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1-1
1.1-2
1 change: 1 addition & 0 deletions .theos/packages/ws.hbang.mapsopener-1.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2-1
1 change: 1 addition & 0 deletions .theos/packages/ws.hbang.mapsopener-1.2~beta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2~beta-37
2 changes: 1 addition & 1 deletion MapsOpener.plist
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
{ Filter = { Bundles = ( "com.apple.MapKit", "com.apple.springboard" ); }; }
56 changes: 53 additions & 3 deletions Tweak.xm
Original file line number Diff line number Diff line change
@@ -1,17 +1,67 @@
/**
* MapsOpener - open Google Maps links in the new app
*
* By Ad@m <http://hbang.ws>
* By HASHBANG Productions <http://hbang.ws>
* Licensed under the GPL license <http://www.gnu.org/copyleft/gpl.html>
*
* The comgooglemaps:// URL scheme is documented on Google Developers:
* <https://developers.google.com/maps/documentation/ios/urlscheme>
*/

#import "HBLibOpener.h"
#import <version.h>
#import <MapKit/MKMapItem.h>

#define PERCENT_ENCODE(string) [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)(string), NULL, CFSTR(":/=,!$& '()*+;[]@#?"), kCFStringEncodingUTF8) autorelease]

%group HBMOiOS6
static NSString *HBMOMakeQuery(MKMapItem *mapItem) {
if (mapItem.isCurrentLocation) {
return @"";
} else {
NSDictionary *info = mapItem.placemark.addressDictionary;

return [NSString stringWithFormat:@"%@%@%@%@%@",
PERCENT_ENCODE([info objectForKey:@"Street"] ? [[info objectForKey:@"Street"] stringByAppendingString:@" "] : @""),
PERCENT_ENCODE([info objectForKey:@"City"] ? [[info objectForKey:@"City"] stringByAppendingString:@" "] : @""),
PERCENT_ENCODE([info objectForKey:@"State"] ? [[info objectForKey:@"State"] stringByAppendingString:@" "] : @""),
PERCENT_ENCODE([info objectForKey:@"ZIP"] ? [[info objectForKey:@"ZIP"] stringByAppendingString:@" "] : @""),
PERCENT_ENCODE([info objectForKey:@"CountryCode"] ?: @"")
];
}
}

%hook MKMapItem
+(NSURL *)urlForMapItems:(NSArray *)items options:(id)options {
if (items.count < 1) {
return %orig;
} else if (items.count == 1) {
return [NSURL URLWithString:[@"comgooglemaps://?q=" stringByAppendingString:HBMOMakeQuery([items objectAtIndex:0])]];
} else {
return [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?saddr=%@&daddr=%@", HBMOMakeQuery([items objectAtIndex:0]), HBMOMakeQuery([items objectAtIndex:1])]];
}
}
%end
%end

%ctor {
if (IS_IOS_OR_NEWER(iOS_6_0)) {
%init(HBMOiOS6);
}

if (![[NSBundle mainBundle].bundleIdentifier isEqualToString:@"com.apple.springboard"]) {
return;
}

[[HBLibOpener sharedInstance] registerHandlerWithName:@"MapsOpener" block:^(NSURL *url) {
if (([url.scheme isEqualToString:@"maps"] || ([url.host hasPrefix:@"maps.google.co"] && [url.path isEqualToString:@"/maps"])) && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
return [NSURL URLWithString:[@"comgooglemaps://search?" stringByAppendingString:[url.scheme isEqualToString:@"maps"] ? [[url.absoluteString stringByReplacingOccurrencesOfString:@"maps:address=" withString:@"maps:q="] stringByReplacingOccurrencesOfString:@"maps:" withString:@""] : url.query]];
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlemaps://"]]) {
return (id)nil;
} else if ([url.scheme isEqualToString:@"maps"]) {
return [NSURL URLWithString:[@"comgooglemaps://?" stringByAppendingString:[[url.absoluteString stringByReplacingOccurrencesOfString:@"maps:address=" withString:@"maps:q="] stringByReplacingOccurrencesOfString:@"maps:" withString:@""]]];
} else if ([url.host hasPrefix:@"maps.google.co"] && [url.path isEqualToString:@"/maps"]) {
return [NSURL URLWithString:[@"comgooglemaps://?" stringByAppendingString:url.query]];
}

return (id)nil;
}];
}
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: ws.hbang.mapsopener
Name: MapsOpener
Pre-Depends: firmware (>= 5.1)
Depends: mobilesubstrate, ws.hbang.libopener
Version: 1.1
Version: 1.2
Architecture: iphoneos-arm
Description: Open Google Maps links in the new App Store app
Maintainer: HASHBANG Productions <mapsopener@hbang.ws>
Expand Down

0 comments on commit bed9ee8

Please sign in to comment.