在 iPhone 中获取行车路线

发布于 2024-09-15 11:31:49 字数 254 浏览 3 评论 0原文

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

我正在寻找一种简单的方法来获取路线数据并使用 iOS 4 SDK 的 Mapkit 中的内置路线显示功能进行显示。

有没有程序员用 Google Map 和 Bing Map 实现这样的功能?由于 Bing Map 在 SOAP Web 服务中提供了路线数据,因此使用 Bing 的服务来编程驾驶方向似乎更容易。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぽ尐不点ル 2024-09-22 11:31:49

我找到了这个问题的解决方案。只需使用 JSON 解析器即可获取 google 地图 API

例如:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文