我为iPhone EULA阅读了iPhone和谷歌地图,并希望在我的iPhone应用程序(本机)中实现静态驾驶方向图。
我在iOS 4 SDK的Mapkit中找到了一种获取路径数据和显示内置路由显示功能的简单方法。
是否有任何程序员使用Google Map和Bing Map实现这样的功能?由于Bing Map在SOAP Web服务中提供了路由数据,因此使用Bing的服务编写行车方向似乎更容易。
答案 0 :(得分:1)
我找到了解决方法。只需使用JSON解析器即可获得谷歌地图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;
}