Question

I read both iPhone and Google Map for iPhone EULA and want to implement a static driving direction map in my iPhone application (native).

I am finding a simple way to get route data and display with build-in route display feature in iOS 4 SDK' Mapkit.

Is there any programmer implement a feature like this with Google Map and Bing Map? Since Bing Map provided routing data in SOAP web service, it's seem easier to programming driving direction with Bing's service.

Was it helpful?

Solution

I found the solution for this. Just use a JSON parser to got google map API

For example:

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top