2013-03-12 79 views
0

我想知道是否有人知道如何獲得經緯度地址列表?iOS - 獲取長/緯度的地址

我一直在使用下面的代碼,但它總是產生一個地址:

[self.geocoder reverseGeocodeLocation: currentLocation completionHandler: 
^(NSArray *placemarks, NSError *error) { 
    for (int i = 0; i < placemarks.count; i++) 
    { 
     CLPlacemark *placemark = [placemarks objectAtIndex:i]; 
     if (placemark.addressDictionary != nil) 
     { 
      Location *aLocation = [[Location alloc] init]; 
      aLocation.locationName = [placemark.addressDictionary valueForKey:@"Name"]; 
      aLocation.locationAddress = [placemark.addressDictionary valueForKey:@"City"]; 
      aLocation.currentLocation = placemark.location; 
      [self.tableData addObject:aLocation]; 
     } 
    } 
    [self.locationsTableView reloadData]; 
}]; 
+0

檢查 這裏getReverseGeocode方法調用這個問題http://stackoverflow.com/questions/158557/get-street-address-at-lat-long-pair – Spire 2013-03-12 15:21:44

+0

http://stackoverflow.com/questions/13557026/can-you-create-an-annotation-in-mapview-from-an-address/13564318#13564318 – Rajneesh071 2013-03-12 15:37:56

+0

你在尋找什麼樣的地址?你想要所有的郵寄地址或只是特定的地標(地點)? – Jeffrey 2013-05-09 19:37:04

回答

0

我不知道,如果核心位置的地理編碼是爲了做到這一點。

Google允許進行此類搜索,但對Places API有限制。話雖如此,你可以搜索「比薩」之類的東西,並獲得半徑內的結果。

欲瞭解更多信息看:https://developers.google.com/places/documentation/

您可以使用自己的API基於緯度/經度與搜索查詢和半徑進行查詢,得到的結果看起來像你以後。

祝你好運!

+0

您是否知道它是否會根據我提供的長/緯度給我X個位置? – Mikerizzo 2013-03-13 18:10:49

+0

是的,我認爲這是重點。您必須閱讀文檔,但如果需要,您可以限制返回多少位置。 – 2013-03-13 18:52:27

0

首先改變你的經緯度值(和檢查可能是你的代碼是正確的)因爲在地圖上,一些座標不提供完整的信息。

以下提供代碼,如果某些座標不提供全部信息,那麼如何才能爲您提供獲取特定CITY(或其他Infor)名稱的條件。
通過[self getReverseGeocode];

- (void) getReverseGeocode 
    { 
     CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 

     if(currentLatLong.count > 0) 
     { 
      CLLocationCoordinate2D myCoOrdinate; 

      myCoOrdinate.latitude = LatValue; 
      myCoOrdinate.longitude = LangValue; 

      CLLocation *location = [[CLLocation alloc] initWithLatitude:myCoOrdinate.latitude longitude:myCoOrdinate.longitude]; 
      [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) 
      { 
       if (error) 
       { 
        NSLog(@"failed with error: %@", error); 
        return; 
       } 
       if(placemarks.count > 0) 
       { 
        NSString *MyAddress = @""; 
        NSString *city = @""; 

        if([placemark.addressDictionary objectForKey:@"FormattedAddressLines"] != NULL) 
         MyAddress = [[placemark.addressDictionary objectForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; 
        else 
         MyAddress = @"Address Not founded"; 

        if([placemark.addressDictionary objectForKey:@"SubAdministrativeArea"] != NULL) 
         city = [placemark.addressDictionary objectForKey:@"SubAdministrativeArea"]; 
        else if([placemark.addressDictionary objectForKey:@"City"] != NULL) 
         city = [placemark.addressDictionary objectForKey:@"City"]; 
        else if([placemark.addressDictionary objectForKey:@"Country"] != NULL) 
         city = [placemark.addressDictionary objectForKey:@"Country"]; 
        else 
         city = @"City Not founded"; 

        NSLog(@"%@",city); 
        NSLog(@"%@", MyAddress); 
       } 
      }]; 
     } 
    }