0

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

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

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

2 回答 2

0

我不确定核心位置的地理编码是否打算这样做。

谷歌允许这种搜索,但他们的 Places API 有限制。话虽如此,您可以搜索“Pizza”之类的内容并在半径范围内获得结果。

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

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

祝你好运!

于 2013-03-12T15:17:27.423 回答
0

首先更改您的纬度和经度值(并检查您的代码是否正确)因为地图中的某些坐标未提供完整信息。

以下提供代码,如果某个坐标未提供完整信息,那么如何为您提供获取特定 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);
                 }
             }];
        }
    }
于 2013-03-12T15:19:24.677 回答