Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone ios:反向地理编码的有效且推荐的方法是什么?_Iphone_Ios_Objective C_Reverse Geocoding - Fatal编程技术网

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

Iphone ios:反向地理编码的有效且推荐的方法是什么?,iphone,ios,objective-c,reverse-geocoding,Iphone,Ios,Objective C,Reverse Geocoding,我要反转某个位置的地理代码纬度和经度,并想得到该位置的地址。我已经通过谷歌网络服务做到了,但这需要时间。 我想知道是否还有其他好的、有效的方法 正在调用此服务 NSString * getAddress = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",Lattitude,Longitude]; 查看GLGeocoder。具体

我要反转某个位置的地理代码纬度和经度,并想得到该位置的地址。我已经通过谷歌网络服务做到了,但这需要时间。 我想知道是否还有其他好的、有效的方法

正在调用此服务

NSString * getAddress = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",Lattitude,Longitude];

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

您可以使用
CLGeocoder

[self.geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error){
    CLPlacemark *placemark = placemarks[0];
    NSLog(@"Found %@", placemark.name);
}];
但这仍然需要时间,因为这两种方法都使用web服务将lat/long转换为一个位置

请尝试以下代码

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);
     }];
看看,或者,如果只是想快速复制:NSArray*addressOutput; CLLocation*当前位置; //假设这些实例变量

// 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);
    }
}];

基于教程中的代码。

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


从该链接查看我的答案类似于您的要求从该链接查看我的另一个关于位置详细信息的答案NSString*locatedAt=[[placemark.addressDictionary valueForKey:@“FormattedAddressLines”]组件通过字符串连接:@“,”];这正是我想要的注意,您不应该在生产代码中使用它。如果出现错误且placemarks为NULL或空,这将使应用程序崩溃。
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')