2010-08-22 3 views
1

Je lis à la fois iPhone et Google Map pour iPhone CLUF et je veux mettre en œuvre une carte de direction de conduite statique dans mon application iPhone (natif).Obtenir la direction de conduite dans l'iPhone

Je trouve un moyen simple d'obtenir des données de route et d'affichage avec la fonction d'affichage de route intégrée dans iOS 4 SDK 'Mapkit.

Y a-t-il des programmeurs qui implémentent une fonctionnalité comme celle-ci avec Google Map et Bing Map? Comme Bing Map fournit des données de routage dans le service Web SOAP, il est plus facile de programmer la direction de conduite avec le service de Bing.

Répondre

1

J'ai trouvé la solution pour cela. Il suffit d'utiliser un analyseur de JSON obtenu google API carte

Par exemple:

NSDictionary *testJsondata = [self testJson:GoogleMapXMLDirectionQueryString]; 
    NSLog(@"Here is the title of the response: %@", [testJsondata valueForKey:@"status"]); 

    for (id key in testJsondata) { 

     NSLog(@"key: %@, value: %@", key, [testJsondata objectForKey:key]); 

    } 
} 

- (NSDictionary *) testJson : (NSString*) url 
{ 
    id response = [self objectWithUrl:[NSURL URLWithString:url]]; 

    NSDictionary *feed = (NSDictionary *)response; 
    return feed; 
} 

- (id) objectWithUrl:(NSURL *)url 
{ 
    SBJsonParser *jsonParser = [SBJsonParser new]; 
    NSString *jsonString = [self stringWithUrl:url]; 

    // Parse the JSON into an Object 
    return [jsonParser objectWithString:jsonString error:NULL]; 
} 

- (NSString *)stringWithUrl:(NSURL *)url 
{ 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url 
               cachePolicy:NSURLRequestReturnCacheDataElseLoad 
              timeoutInterval:30]; 
    // Fetch the JSON response 
    NSData *urlData; 
    NSURLResponse *response; 
    NSError *error; 

    // Make synchronous request 
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest 
            returningResponse: &response 
               error: &error]; 

    // Construct a String around the Data from the response 
    return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]; 
} 

- (NSString *)getDirectionInXML:(NSString *)GoogleMapXMLDirectionQueryString 
{ 
    NSError *error; 
    NSURLResponse *response; 
    NSData *dataReply; 
    NSString *stringReply; 

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: 
            [NSURL URLWithString: [NSString stringWithFormat:GoogleMapXMLDirectionQueryString]]]; 
    [request setHTTPMethod: @"GET"]; 
    dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
    stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding]; 
    return stringReply; 
} 
Questions connexes