Convert iPhone GPS to address
I have been researching a few different apps lately for my company which are all able to convert your current GPS location to an address. I have been googling and searching through the stack but I can't seem to find an开发者_如何学JAVAy helpful information on the net to tell me how to achieve this. So my question is this; how do you:
a) get your current GPS coordinates and then
b) transform them into a real address i.e. street number/name, city, countrya) get your current GPS coordinates
You need to use CLLocationManager for that (you may need to store manager to release it when it no longer will be needed) -
CLLocationManager* manager = [[CLLocationManager alloc] init];
manager.delegate = self;
//Set location manager's properties if needed
[manager startUpdatingLocation];
Then your delegate object will be able to receive messages when GPS location updates (or fails to do that):
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
b) transform them into a real address
After you have gps coordinate of tour location you can create MKReverseGeocoder
object to query google reverse geocoding service. If request succeeds geocoder's delegate will receive MKPlacemark
object with address info.
Use MKReverseGeocoder
http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKReverseGeocoder_Class/Reference/Reference.html
MKReverseGeocoder is deprecated in iOS 5.0. Use the CLGeocoder class instead.
https://developer.apple.com/reference/corelocation/clgeocoder
精彩评论