2013-03-12 39 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); 
       } 
      }]; 
     } 
    } 
相关问题