Convert iPhone GPS to address

前端 未结 3 1362
庸人自扰
庸人自扰 2020-12-12 01:09

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

3条回答
  •  抹茶落季
    2020-12-12 01:51

    a) 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.

提交回复
热议问题