Ios 如何将经度和纬度转换为点
我正在努力获取当前位置的经度和纬度,我正在使用代码Ios 如何将经度和纬度转换为点,ios,android-mapview,Ios,Android Mapview,我正在努力获取当前位置的经度和纬度,我正在使用代码 locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move locationManager.desiredAccuracy = kCLLocationAccura
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Latitude : %@",lat);
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
// longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
// degrees, minutes, seconds];
longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Longitude : %@",longt);
}
以及获得:
当前纬度:37°47'9.0024“
当前经度:-122°24'23.1012“
但是我想要像13.233233这样的纬度和经度(以点为单位)。那么我如何将其转换为经度和纬度?请提供帮助。为什么要使用此折旧方法在iOS 7中使用此方法获取位置。使用这种方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// location_updated = [locations lastObject];
// NSLog(@"updated coordinate are %@",location_updated);
float currentLocationLati = [[locations objectAtIndex:0] coordinate].latitude;
float currentLocationLong = [[locations objectAtIndex:0] coordinate].longitude;
}
通过这种方法,您将发现更新纬度和经度只需使用它们,不要从下面的答案中将它们转换为度
其中R是地球的近似半径(例如6371KM)。在newLocation.coordinate.latitude和newLocation.coordinate.longitude中,你有你想要的值,只是不转换它们。你所说的“点”到底是什么意思?在笛卡尔坐标系中。在什么坐标系的笛卡尔坐标系中?UIView还是MKMapView?目的是什么?如果您只想以十进制格式显示它们,请执行NSLog(@“lat,long=%f,%f”,newLocation.coordinate.latitude,newLocation.coordinate.longitude)代码>。另外,这不是一个“android地图视图”。这是一个更新位置的数组,我更新我的答案,你可以从那里得到浮动的纬度和经度
x = R * cos(lat) * cos(lon)
y = R * cos(lat) * sin(lon)
z = R *sin(lat)