IPhone obtains current location information

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.