2013-07-22 20 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