2016-04-06 38 views
0

我正在通過使用SPGooglePlacesAutoComplete github庫實施谷歌地點自動完成API的MapKit。 在仔細實施所有最後階段後,我想將我的Annotation移動到用戶選定的位置,它會給出錯誤Domain=kCLErrorDomain Code=8
用戶從自動完成結果中選擇特定位置後會發生這種情況。所以這是我在做什麼,我didSelectRowAtIndexPath方法:來自Place的CLPlacemark無法映射所選地點

[self.searchDisplayController setActive:NO animated:YES]; 
SPGooglePlacesAutocompletePlace *place = [placesArray objectAtIndex:indexPath.row]; 

[place resolveToPlacemark:^(CLPlacemark *placemark, NSString *addressString, NSError *error) { 
    if (error) { 
     SPPresentAlertViewWithErrorAndTitle(error, @"Could not map the selected Place"); 

    }else if (placemark) { 

     [selectedPlaceAnnotation setCoordinate:placemark.location.coordinate]; 

     locationLat = selectedPlaceAnnotation.coordinate.latitude; 
     locationLon = selectedPlaceAnnotation.coordinate.longitude; 

     [defaults setFloat:locationLat forKey:@"locLat"]; 
     [defaults setFloat:locationLon forKey:@"locLon"]; 


     selectedPlaceAnnotation.title = @"You Selected This Location"; 

     if (![self.MapView.annotations containsObject:selectedPlaceAnnotation]==YES) { 
      [self.MapView addAnnotation:selectedPlaceAnnotation]; 
     } 

     //[self.MapView animateToLocation:placemark.location.coordinate]; 

     MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(placemark.location.coordinate, 800, 800); 
     [self.MapView setRegion:[self.MapView regionThatFits:region] animated:YES]; 


      [self.searchDisplayController.searchResultsTableView deselectRowAtIndexPath:indexPath animated:NO]; 
     } 
} 
    ]; 

如果我打印resolveToPlacemark參數我得到這個Placemark = (null) Address String = (null) Error = Error Domain=kCLErrorDomain Code=8 "(null)"

+0

你可以請檢查對象的地方? –

+0

@ VishnuKumar.S位置對象正在打印從搜索結果中選擇的正確值。 –

回答

0

請更改searchQuery.typesSPPlaceTypeGeocode如果它被設置爲SPPlaceTypeEstablishment

+0

我解決了它...這是'searchQuery.types'設置爲'SPPlaceTypeEstablishment'的錯誤,我只是將其更改爲'SPPlaceTypeGeocode',現在它正在工作 –

+0

好的,很高興得知您的問題已修復: ) –

+0

更新我在答案中寫的內容,以便我可以將其標記爲正確。 –

相關問題