Вопрос

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.

Это было полезно?

Решение

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");
    }
}

Другие советы

- (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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top