2016-11-29 90 views
3

在我的應用程序中使用位置字符串進行搜索時,它將返回5結果,但與默認設備映射應用程序不匹配。Apple CLGeocoder,MKLocalSearch結果與設備映射結果不同

我的代碼1:CLGeocoder

CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
[geocoder geocodeAddressString:searchKey completionHandler:^(NSArray* placemarks, NSError* error){ 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     if (placemarks.count > 0) { 
      searchLocations = placemarks; 
     } else { 
      searchLocations = nil; 
     } 
     [searchTableView reloadData]; 

     for (CLPlacemark *placemark in placemarks) { 
      NSLog(@"place dic %@",placemark.addressDictionary); 
     } 
    }); 
}]; 

代碼2:MKLocalSearch

CLLocation *userLoc = (CLLocation *)[[MYLocationManager defaultManager] currentLocation]; 
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init]; 
request.region = MKCoordinateRegionMakeWithDistance(userLoc.coordinate, 100000, 100000); 
request.naturalLanguageQuery = searchKey; 
MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request]; 
[search startWithCompletionHandler:^(MKLocalSearchResponse * _Nullable response, NSError * _Nullable error) { 
    NSMutableArray *locs = [[NSMutableArray alloc]init]; 
    for (MKMapItem *placeM in response.mapItems) { 
     [locs addObject:placeM.placemark]; 
    } 
    if (locs.count > 0) { 
     searchLocations = locs; 
    } else { 
     searchLocations = nil; 
    } 


    dispatch_async(dispatch_get_main_queue(), ^{ 
    [searchTableView reloadData]; 
    }); 
}]; 

兩者都返回相同的結果 CLGeocoder result

設備地圖應用程序中的結果:

DEvice map result

設備映射結果與編碼地理結果不同。請幫忙解決這個問題。 和我的問題是什麼類型的搜索方法使用默認地圖應用程序? 以及如何在編碼中獲得相同的結果?

回答

0

請參考this的答案。它描述了複製上述結果所需的所有步驟。我已經在模擬器上測試過了。