位置和地图编程指南可以提供很多使用设备位置的帮助。Techtopia 还提供了关于 CLLocationManager 使用的教程。这是一个片段,它引用了一个 CLLocation 变量newLocation.coordinate.latitude
和经度newLocation.coordinate.longitude
(请参阅来源以获取更多信息):
#pragma mark -
#pragma mark CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSString *currentLatitude = [[NSString alloc]
initWithFormat:@"%g",
newLocation.coordinate.latitude];
latitude.text = currentLatitude;
NSString *currentLongitude = [[NSString alloc]
initWithFormat:@"%g",
newLocation.coordinate.longitude];
longitude.text = currentLongitude;
NSString *currentHorizontalAccuracy =
[[NSString alloc]
initWithFormat:@"%g",
newLocation.horizontalAccuracy];
horizontalAccuracy.text = currentHorizontalAccuracy;
NSString *currentAltitude = [[NSString alloc]
initWithFormat:@"%g",
newLocation.altitude];
altitude.text = currentAltitude;
NSString *currentVerticalAccuracy =
[[NSString alloc]
initWithFormat:@"%g",
newLocation.verticalAccuracy];
verticalAccuracy.text = currentVerticalAccuracy;
if (startLocation == nil)
self.startLocation = newLocation;
CLLocationDistance distanceBetween = [newLocation
distanceFromLocation:startLocation];
NSString *tripString = [[NSString alloc]
initWithFormat:@"%f",
distanceBetween];
distance.text = tripString;
}