å°å³ã¢ããªãä½ç½®æ å ±ã渡ãã¦èµ·åããããå ´åãã©ã®ããã«ãã¦é£æºèµ·åãè¡ãã®ãããç´¹ä»ãããã¨æãã¾ãã
UIApplicationã¯ã©ã¹
ã¯ã¢ããªã±ã¼ã·ã§ã³å
¨ä½ã管çããã¯ã©ã¹ã§ããcanOpenURL:ã¡ã½ãã
ã§å®éã«éããã¨ãå¯è½ãªURLãªã®ãã©ããå¤å®ãããã®ä¸ã§openURL:ã¡ã½ãã
ã使ã£ã¦å°å³ã¢ããªãèµ·åãã¦ãã¾ãã
å°å³ã¢ããªã«ä½ç½®åº§æ¨ã渡ãã¦é£æºèµ·åãã(iOS 6ã)
iOS 5ã¾ã§ã¯ãiPhoneã®æ¨æºå°å³ã¢ããªã¨è¨ãã°ãGoogleããããã使ããã¦ãã¾ãããããããiOS 6ã§ã¯Googleããã§ã¯ãªãAppleèªèº«ãåå½ã®å°å³é 給ä¼ç¤¾ã¨ç´æ¥ææºãã¦éçºããå°å³ã¢ããªãæ¨æºå°å³ã¢ããªã¨ãªãã¾ããã
å°å³ãã¼ã¿ã®é 給ä¼ç¤¾ã¨ãã¦ã¯ãæµ·å¤ãTomTom社ãã¯ããè¤æ°ç¤¾ãæ¥æ¬ã§ã¯[ã¤ã³ã¯ãªã¡ã³ãã»ãã¼]社(http://www.incrementp.co.jp/)ã®ãã¼ã¿ã使ãããããã«ãªã£ã¦ãã¾ã*1ã
ã«ã¹ã¿ã URLã¹ãã¼ã ãhttp://maps.apple.com/
ã«å¤æ´ããã¦ãã¾ãã
NSString *format = @"http://maps.apple.com/maps?ll=%1.6f,%1.6f"; NSString* urlString = [NSString stringWithFormat:format, 35.668194, 139.601111]; NSURL* url = [NSURL URLWithString:urlString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; }
ä¸è¨ã®ãµã³ãã«ã³ã¼ããå®è¡ããã¨ä¸å³ã®ããã«ãå°å³ã¢ããªãèµ·åãæå®ããä½ç½®åº§æ¨ã®å ´æã表示ãã¦ãããã¨ããããã¾ãã
åºçºå°ç¹ã¨å°çå°ç¹ãæå®ãã¦å°å³ã¢ããªãèµ·åããã(iOS 6ã)
iOS 6以é対å¿ã®ã¢ããªã§ã®åºçºç¹ã¨å°çå§ç¹ãæå®ãã¦ãå°å³ã¢ããªãèµ·åããããã«ã¯ã©ãããã°ããã§ãããããiOS 5以åã¨åãããã«saddr
ã«åºçºå°ç¹ãdaddr
ãæå®ãã¦openURL:ã¡ã½ãã
ãå®è¡ãã¾ãã
iOS 5以åã¨ã®ã«ã¹ã¿ã URLã¹ãã¼ãã®éãã¯ãã¡ã¤ã³é¨åã ãã¨ãªãã¾ãã
// åºçºç¹ NSString *name1 = @"大éªé§ "; NSString *encName1 = [name1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // å°çç¹ NSString *name2 = @"大éªå¸ååº"; NSString *encName2 = [name2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString* urlstr = [NSString stringWithFormat:@"http://maps.apple.com/?saddr=%@&daddr=%@", encName1, encName2]; NSURL* url = [NSURL URLWithString: urlstr]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; }
ä¸è¨ã®ãµã³ãã«ã³ã¼ããå®è¡ããã¨ä¸å³ã®ããã«ãå°å³ã¢ããªãèµ·åãé è·¯ã表示ããã¦ããã®ãåããã¾ãã
å°å³ã¢ããªã«ä½ç½®åº§æ¨ã渡ãã¦é£æºèµ·åãã(ãiOS 5)
åè¿°ããéããiOS 6以éã¯æ¨æºã®å°å³ã¢ããªãAppleç¬èªã®ãã®ã«ãªã£ã¦ãã¾ã£ããããiOS 5ã§ã¯æ¨æºå°å³ã¢ããªãèµ·åã§ãã¦ããä¸è¨ã®ã«ã¹ã¿ã URLã使ç¨ããã¨ãGoogleãããã¢ããªãèµ·åãã¾ãã
NSString *name = [item valueForKey:@"æ¡å±±å¤§å¦"]; NSString *encName = [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString* urlstr = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%1.6f,%1.6f", encName, 135.5583577, 34.8477655]; NSURL* url = [NSURL URLWithString: urlstr]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; }
åºçºå°ç¹ã¨å°çå°ç¹ãæå®ãã¦å°å³ã¢ããªãèµ·åããã(ãiOS 5)
ä»ã«ãã«ã¹ã¿ã URLã¹ãã¼ã ã«ã©ã®ãããªãã©ã¡ã¼ã¿ãããã®ã調ã¹ã¦ã¿ã¾ããã
ä¾ãã°ãå°å³ã¢ããªã§ã«ã¼ãæ¤ç´¢ããããªãå ´åã«ã¯ãåºçºå°ç¹ã«saddr=
ãå°çå°ç¹ã«daddr=
ãæå®ãã¾ãã大éªé§
ãã大éªååºã¸ã®ã«ã¼ãã表示ãããå ´åã«ã¯ãURLã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
ã³ã¼ãã§æ¸ãã¨ä»¥ä¸ã®éãã§ãã
// åºçºç¹ NSString *name1 = @"大éªé§ "; NSString *encName1 = [name1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // å°çç¹ NSString *name2 = @"大éªå¸ååº"; NSString *encName2 = [name2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString* urlstr = [NSString stringWithFormat:@"http://maps.google.co.jp/maps?saddr=%@&daddr=%@", encName1, encName2]; NSURL* url = [NSURL URLWithString: urlstr]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; }
iOS 7ã·ãã¥ã¬ã¼ã¿ã«ã¦ä¸è¨ã®ãµã³ãã«ã³ã¼ããå®è¡ããã¨ãä¸å³ã®ããã«Safariä¸ã§Google Mapsã表示ããã¾ãã
åè
ä»ã«ã沢山ãã©ã¡ã¼ã¿ãåå¨ãã¦ããã®ã§ãApple社ã®ããã¥ã¡ã³ããç´¹ä»ãã¾ãã
*1:å°å³ã¢ããªã®ã©ã¤ã»ã³ã¹æ¬åç §