kam*_*iro 11 geolocation reverse-geocoding ios
我在这里看到另一个问题:确定iPhone用户的国家/地区可以获得iPhone用户所在的当前国家/地区.
这对于许多用途来说非常方便.但是,是否可以更深入地推断iOS(如果有信息)用户所处的州或城市?
如果事情不可能的话,我认为反向地理编码服务将是下一步.有没有可以为您的应用程序雇用的反向地理编码服务?
fen*_*ngd 26
MKReverseGeocoder
在iOS 5中已弃用,现在已经过时了 CLGeocoder
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {
.... = [placemark locality];
}
}];
}
Run Code Online (Sandbox Code Playgroud)
Ank*_*yas 24
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
CLLocation *newLocation = [[CLLocation alloc]initWithLatitude:21.1700
longitude:72.8300];
[geocoder reverseGeocodeLocation:newLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
NSLog(@"Geocode failed with error: %@", error);
return;
}
if (placemarks && placemarks.count > 0)
{
CLPlacemark *placemark = placemarks[0];
NSDictionary *addressDictionary =
placemark.addressDictionary;
NSLog(@"%@ ", addressDictionary);
NSString *address = [addressDictionary
objectForKey:(NSString *)kABPersonAddressStreetKey];
NSString *city = [addressDictionary
objectForKey:(NSString *)kABPersonAddressCityKey];
NSString *state = [addressDictionary
objectForKey:(NSString *)kABPersonAddressStateKey];
NSString *zip = [addressDictionary
objectForKey:(NSString *)kABPersonAddressZIPKey];
NSLog(@"%@ %@ %@ %@", address,city, state, zip);
}
}];
Run Code Online (Sandbox Code Playgroud)
结果
{
City = Surat;
Country = India;
CountryCode = IN;
FormattedAddressLines = (
Surat,
Gujarat,
India
);
Name = Surat;
State = Gujarat;
}
2012-12-20 21:33:26.284 CurAddress[4110:11603] (null) Surat Gujarat (null)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
30632 次 |
最近记录: |