Open maps with specific address iOS 7

后端 未结 5 1074
半阙折子戏
半阙折子戏 2021-02-19 04:14

I am trying to make my application open the apple maps application and have the address be pulled up. I tried this :

- (IBAction)openInMaps:(id)sender {
    NSS         


        
5条回答
  •  臣服心动
    2021-02-19 04:30

    This is how I do it in Objective C...I always try the Waze Map first, because to be honest, it's awesome sauce, I added the PLIST file permissions at the end:

    - (IBAction)getDirectionsAction:(id)sender {
        NSURL *googleURL = [[NSURL alloc]
            initWithString:[NSString stringWithFormat:@"comgooglemaps://?daddr=%@", @"44.294349,-70.326973"]];
    
        NSURL *googleWebURL =
            [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.maps.google.com/maps?daddr=%@",
                                                                     @"44.294349,-70.326973"]];
    
        NSURL *appleURL = [NSURL URLWithString:@"http://maps.apple.com/?daddr=311+East+Buckfield+Road+Buckfield+Maine"];
    
        NSURL *wazeURL = [NSURL URLWithString:@"waze://?ll=44.294349,-70.326973&navigate=yes"];
    
        // Lets try the Waze app first, cuz we like that one the most
        if ([[UIApplication sharedApplication] canOpenURL:wazeURL]) {
            [[UIApplication sharedApplication] openURL:wazeURL
                                               options:@{}
                                     completionHandler:^(BOOL success){
                                     }];
            return;
        }
    
        // Lets try the Apple Maps app second (great success rate)
        if ([[UIApplication sharedApplication] canOpenURL:appleURL]) {
            [[UIApplication sharedApplication] openURL:appleURL
                                               options:@{}
                                     completionHandler:^(BOOL success){
                                     }];
            return;
        }
        // If those 2 are unsuccessful, let's try the Google Maps app
        if ([[UIApplication sharedApplication] canOpenURL:googleURL]) {
            [[UIApplication sharedApplication] openURL:googleURL
                                               options:@{}
                                     completionHandler:^(BOOL success){
                                     }];
            return;
        }
        // Uh, oh...Well, then lets launch it from the web then.
        else {
            [[UIApplication sharedApplication] openURL:googleWebURL
                                               options:@{}
                                     completionHandler:^(BOOL success){
    
                                     }];
        }
    }
    

    FOR PLIST FILE

    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
        NSExceptionDomains
        
            http://maps.apple.com
            
                NSExceptionAllowsInsecureHTTPLoads
                
                NSExceptionRequiresForwardSecrecy
                
                NSIncludesSubdomains
                
            
            http://maps.google.com/
            
                NSIncludesSubdomains
                
                NSExceptionAllowsInsecureHTTPLoads
                
                NSExceptionRequiresForwardSecrecy
                
            
        
    
    LSApplicationQueriesSchemes
    
        waze
        comgooglemaps
    
    NSLocationAlwaysUsageDescription
    For Use for directions
    

提交回复
热议问题