在iPhone中获取驾驶方向

在iPhone中获取驾驶方向,iphone,soap,mapkit,bing-maps,driving-directions,Iphone,Soap,Mapkit,Bing Maps,Driving Directions,我阅读了iPhone和Google Map for iPhone EULA,希望在我的iPhone应用程序(本机)中实现静态驾驶方向图 我正在寻找一种简单的方法,通过iOS 4 SDK的Mapkit中的内置路由显示功能获取路由数据并进行显示 有没有程序员用谷歌地图和必应地图实现这样的功能?由于Bing地图在SOAP web服务中提供了路由数据,因此使用Bing的服务编程驾驶方向似乎更容易。我找到了解决方案。只需使用JSON解析器就可以获得GoogleMapAPI 例如: NSDictionary

我阅读了iPhone和Google Map for iPhone EULA,希望在我的iPhone应用程序(本机)中实现静态驾驶方向图

我正在寻找一种简单的方法,通过iOS 4 SDK的Mapkit中的内置路由显示功能获取路由数据并进行显示


有没有程序员用谷歌地图和必应地图实现这样的功能?由于Bing地图在SOAP web服务中提供了路由数据,因此使用Bing的服务编程驾驶方向似乎更容易。

我找到了解决方案。只需使用JSON解析器就可以获得GoogleMapAPI

例如:

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;
}

我找到了解决办法。只需使用JSON解析器就可以获得GoogleMapAPI

例如:

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;
}