A geocoder object uses a network service to convert between latitude and longitude values and a user-friendly placemark, which is a collection of data such as the street, city, state, and country information. Reverse geocoding is the process of converting a latitude and longitude into a placemark. Forward geocoding is the process of converting place name information into a latitude and longitude value. Reverse geocoding is supported in all versions of iOS but forward geocoding is supported only in iOS 5.0 and later.
Function That get currunt address
-------------------------------------------------------------
-(void)getAddressFromCurruntLocation:(CLLocation *)location{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if(placemarks && placemarks.count > 0)
{
CLPlacemark *placemark= [placemarks objectAtIndex:0];
//address is NSString variable that declare in .h file.
address = [[NSString stringWithFormat:@"%@ , %@ , %@",[placemark thoroughfare],[placemark locality],[placemark administrativeArea]] retain];
NSLog(@"New Address Is:%@",address);
}
}];
}
-------------------------------------------------------------
Function That get currunt address
-------------------------------------------------------------
-(void)getAddressFromCurruntLocation:(CLLocation *)location{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if(placemarks && placemarks.count > 0)
{
CLPlacemark *placemark= [placemarks objectAtIndex:0];
//address is NSString variable that declare in .h file.
address = [[NSString stringWithFormat:@"%@ , %@ , %@",[placemark thoroughfare],[placemark locality],[placemark administrativeArea]] retain];
NSLog(@"New Address Is:%@",address);
}
}];
}
-------------------------------------------------------------
Additional References
Hope this will useful for getting current address. If any suggestion or improvement then please share it. Thank You....:)
Hi
ReplyDeleteSometimes I am not getting address when I run the reverse-geo code. It returns null.
Do you have any idea about this?
Its not working every time,Its not returning the locality name.
ReplyDelete