Pregunta

Since I have updated my ios to 7.I dont know how get the current location and altitude with the new method

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

Can Any one show me some sample code how to use this method to get current location and altitude?

Thanks a LOT.

¿Fue útil?

Solución

The most recent location will be at the end of the locations array.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *mostRecentLocation = [locations lastObject];
    bool haveValidAltitude = (mostRecentLocation.verticalAccuracy > 0);
    if(haveValidAltitude)
    {
        NSLog(@"current altitude is: %g meters above sea level", mostRecentLocation.altitude);
    }else{
        NSLog(@"current altitude is unavailable");
    }
}

Otros consejos

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations lastObject];
    NSLog(@"latitude %+.6f, longitude %+.6f\n", location.coordinate.latitude, location.coordinate.longitude);
}

locations is an array, last object of which is the newest available location.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top