iOS - 获取Long / Lat周围的地址

时间:2013-03-12 15:10:15

标签: iphone ios geocoding

我想知道是否有人知道如何获得经度和纬度的地址列表?

我一直在使用以下代码,但它总是产生一个地址:

[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];
 }];

2 个答案:

答案 0 :(得分:0)

我不确定Core Location的地理编码是否打算这样做。

Google允许进行此类搜索,但限制使用其Places API。话虽这么说,你可以搜索像“比萨饼”这样的东西,并获得半径范围内的结果。

有关详细信息,请查看:https://developers.google.com/places/documentation/

您可以使用他们的API根据带有搜索查询和半径的纬度/经度进行查询,以获得看起来像您所追求的结果。

祝你好运!

答案 1 :(得分:0)

首先更改你的纬度和经度值(并检查你的代码是否正确)becoze in map,某些坐标不提供完整的信息。

以下提供代码,如果某些坐标不提供完整信息,那么如何为您提供获取特定CITY(或其他Infor )名称的条件。
getReverseGeocode

[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);
                 }
             }];
        }
    }
相关问题