2012-12-17 95 views
0

我使用REQUEST_DENIED iOS上的谷歌地圖API

-(void) getRouteData :(double)startPointLatitude :(double)startPointLongitude :(double)stopPointLatitude :(double)stopPointLongitude{ 

    NSString *url = @"http://maps.apple.com/maps/api/directions/json?"; 

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; 

    [request setHTTPMethod:@"POST"]; 
    [request setTimeoutInterval:15]; 

    NSString *postString; 

    postString = [@"" stringByAppendingFormat: @"origin=%f,%f&destination=%f,%f&sensor=true&mode=driving", startPointLatitude, startPointLongitude, stopPointLatitude, stopPointLongitude]; 

    NSLog(@"%@%@",url, postString); 

    [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

    Boolean isDataGet = false; 

    if (theConnection) { 
     NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
     NSString *result = [NSString stringWithFormat:@"%@", [self hexToString:data]]; 

     NSLog(@"result = %@", result); 

    } 

} 

借鑑谷歌地圖路線起點和終點,但我得到

{ 
    "routes" : [], 
    "status" : "REQUEST_DENIED" 
} 

而且當我添加API密鑰這是行不通的無論是。 (我已經啓用的地方API太)

回答

0

我這個功能解決的問題

-(void) getRouteData :(double)startPointLatitude :(double)startPointLongitude :(double)stopPointLatitude :(double)stopPointLongitude{ 

    NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&sensor=true&mode=driving", startPointLatitude, startPointLongitude, stopPointLatitude, stopPointLongitude]; 

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:apiUrlStr]]; 

    [request setTimeoutInterval:15]; 

    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

    Boolean isDataGet = false; 

    if (theConnection) { 
     NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
     NSString *result = [NSString stringWithFormat:@"%@", [self hexToString:data]]; 

     NSLog(@"result = %@", result); 

    } 

}