ios:反向地理编码的有效和推荐方法是什么?

问题描述 投票:2回答:6

我要反转某个位置的地理编码纬度和经度,并希望获取该位置的地址。我已经通过Google Web Service完成了,但是需要时间。我想知道是否还有其他好的有效方法。

当前正在调用此服务,

NSString * getAddress = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",Lattitude,Longitude];
iphone ios objective-c reverse-geocoding
6个回答
10
投票

您可以使用CLGeocoder

[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error){
    CLPlacemark *placemark = placemarks[0];
    NSLog(@"Found %@", placemark.name);
}];

尽管这仍然需要时间,因为这两种方法都使用Web服务将经/纬度转换为位置


5
投票

尝试此代码。

geoCoder = [[CLGeocoder alloc]init];
    [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:

     //Getting Human readable Address from Lat long,,,

     ^(NSArray *placemarks, NSError *error) {
         //Get nearby address
         CLPlacemark *placemark = [placemarks objectAtIndex:0];
            //String to hold address
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
            //Print the location to console
         NSLog(@"I am currently at %@",locatedAt);
     }];

2
投票

看看GLGeocoder。具体来说reverseGeocodeLocation:completionHandler:


2
投票

您可以使用Apple的CLGeocoder(CoreLocation的一部分)。具体来说,– reverseGeocodeLocation:completionHandler:方法将返回给定坐标的地址数据字典。


1
投票

看看this tutorial,或者,如果只是想快速复制一些内容:NSArray * addressOutput;CLLocation * currentLocation;//假定这些实例变量

// Reverse Geocoding
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    if (error == nil && [placemarks count] > 0) {
        NSMutableArray *tempArray = [[NSMutableArray alloc] initWithCapacity:[placemarks count]];
        for (CLPlacemark *placemark in placemarks) {
            [tempArray addObject:[NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                                  placemark.subThoroughfare, placemark.thoroughfare,
                                  placemark.postalCode, placemark.locality,
                                  placemark.administrativeArea,
                                  placemark.country]];
        }
        addressOutput = [tempArray copy];
    }
    else {
        addressOutput = nil;
        NSLog(@"%@", error.debugDescription);
    }
}];

基于本教程中的代码。


0
投票

如果您不想使用Google API,请尝试以下代码-基本上将纬度和经度输入转换为ZIP(可以调整为地址)。

pip install uszipcode

# Import packages
from uszipcode import SearchEngine
search = SearchEngine(simple_zipcode=True)
from uszipcode import Zipcode
import numpy as np

#define zipcode search function
def get_zipcode(lat, lon):
    result = search.by_coordinates(lat = lat, lng = lon, returns = 1)
    return result[0].zipcode

#load columns from dataframe
lat = df_shooting['Latitude']
lon = df_shooting['Longitude']

#define latitude/longitude for function
df = pd.DataFrame({'lat':lat, 'lon':lon})

#add new column with generated zip-code
df['zipcode'] = df.apply(lambda x: get_zipcode(x.lat,x.lon), axis=1)

#print result
print(df)

#(optional) save as csv
#df.to_csv(r'zip_codes.csv')
© www.soinside.com 2019 - 2024. All rights reserved.