In addition to the CLLocation library, Mapkit can also be used to obtain information about the current location. I personally think Mapkit is more useful and convenient when you need more accurate location information. the usage is as follows:
-(Void) reverseGeocoder :( MKReverseGeocoder *) geocoderdidFailWithError :( NSError *) error
{
NSLog (@ "MKReverseGeocoder has failed .");
}
This function is not explained. You can understand it by name ~
-(Void) reverseGeocoder :( MKReverseGeocoder *) geocoderdidFindPlacemark :( MKPlacemark *) placemark
{
CurrentCityLabel. text = placemark. locality;
}
// Use CLLoction to obtain the current latitude and longitude
-(Void) locationManager :( CLLocationManager *) managerdidUpdateToLocation :( CLLocation *) newLocationfromLocation :( CLLocation *) oldLocation
{
CLLocationDistance l = newLocation. coordinate. latitude; // obtain the longitude
CLLocationDistance v = newLocation. coordinate. longdistance; // obtain the latitude.
NSLog (@ "% f", l, v );
CLLocation * new = [[CLLocation alloc] initWithLatitude: 11.0 longpolling: 12.0];
CLLocationDistance u = [newLocation distanceFromLocation: new];
NSLog (@ "% f", u );
[SelfstartedReverseGeoderWithLatitude: l longdistance: v];
}
-(Void) startedReverseGeoderWithLatitude :( double) latitudelong.pdf :( double) longdistance {
CLLocationCoordinate2D coordinate2D;
Coordinate2D. longpolling = longpolling;
Coordinate2D. latitude = latitude;
MKReverseGeocoder * geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate: coordinate2D];
GeoCoder. delegate = self;
[GeoCoderstart];
}
# Pragma mark-
-(Void) reverseGeocoder :( MKReverseGeocoder *) geocoderdidFindPlacemark :( MKPlacemark *) placemark
{
NSLog (@ "current city: % @", placemark. locality );
}
-(Void) reverseGeocoder :( MKReverseGeocoder *) geocoderdidFailWithError :( NSError *) error
{
}
Initialize geocoder and use the current latitude and longitude information to initialize geocoder
Geocoder contains many parameters, such as city name, street, and so on.
This is an excerpt from the column of the advanced coders.