我正在使用适用于 iOS 的 Google Places API,我需要将一个字符串从其中一个类 (GooglePlacesConnection) 传递给 GooglePlacesObject。
在这里,在第一堂课中,我将 distanceMatrixURL 设置为等于字符串 timeURL
timeURL = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/distancematrix/json?origins=%f,%f&destinations=%@,%@&sensor=true",userLat,userLng,destLat,destLng];
GooglePlacesObject *googleplacesobject = [[GooglePlacesObject alloc]init];
googleplacesobject.distanceMatrixURL = timeURL;
NSLog(@"pullurl is %@", googleplacesobject.distanceMatrixURL);
并且 NSLog 正确打印出 googleplacesobject.distanceMatrixURL。但是,在第二节课上,当我这样做时
-(void)distanceMatrix{
NSLog(@"%@",distanceMatrixURL);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:distanceMatrixURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10];
_connection2 = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
[_connection2 start];
if (_connection2)
{
responseData2 = [NSMutableData data];
connectionIsActive = YES;
NSLog(@"connection is active with %@", responseData2);
} else {
NSLog(@"connection failed");
}
}
NSLog 的 NSLog(@"%@",distanceMatrixURL); 一片空白)