2013-07-22 26 views
0

我使用Google Maps SDK for iOS版本1.4.0.4450从我的iOS应用中显示谷歌街景。 如果街道视图可用,它工作正常。如何检查谷歌街景是否适用于特定位置坐标

我的问题是如果街景不可用如何检查它?

有一个类GMSPanoramaService。它包含一个公共成员方法。我认为这可能有用。 - requestPanoramaNearCoordinate:回调: 检索关于给定坐标附近的全景图的信息。

但是如何使用它?

在此先感谢!

回答

-1

你可以使用这个方法粗鲁

-(void)isStreetViewAvailable:(CLLocationCoordinate2D)location completionBlock: (NWisStreetViewCompletionBlock)completionBlock 
{ 
NSString *loc = [NSString stringWithFormat:@"%.10f,%.10f&", location.latitude, location.longitude]; 
NWisStreetViewCompletionBlock completeBlock = [completionBlock copy]; 


NSString *connectionString = [NSString stringWithFormat:@"http://cbk0.google.com/cbk?output=json&ll=%@", loc]; 
NSLog(@"connect to: %@",connectionString); 

NSURL *url = [NSURL URLWithString:connectionString]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
AFJSONRequestOperation *operation; 
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 
    //NSLog(@"%@", JSON); 

    NSLog(@"%@", JSON); 

    if([JSON objectForKey:@"Location"] == nil) 
     completeBlock(@"", nil); 

    //NSLog(@"panoId: %@",[[json objectForKey:@"Location"] objectForKey:@"panoId"]); 

    completeBlock([[JSON objectForKey:@"Location"] objectForKey:@"panoId"], nil); 



} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 

    NSMutableDictionary* details = [NSMutableDictionary dictionary]; 
    [details setValue:[error description] forKey:NSLocalizedDescriptionKey]; 
    // populate the error object with the details 
    NSError *err = [NSError errorWithDomain:@"world" code:200 userInfo:details]; 

    completeBlock(NO, err); 
}]; 

[operation start]; 



} 
+0

此代码是不完整的,没有被定义NWisStreetViewCompletionBlock –

+0

无效的typedef(^ NWisStreetViewCompletionBlock)(*的NSString panoIdOfPlace,NSError *误差); –

+0

当然,认为这很容易:) – nerowolfe