繁体   English   中英

如何转换点的经度和纬度

[英]How we can convert the Longitude and Latitude in points

我正在使用代码获取当前位置的经度和纬度

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;

    }

通过这种方法,您会发现更新纬度和经度只是使用它们而不会将它们转换为度

从以下答案中将经度\\纬度转换为笛卡尔坐标

x = R * cos(lat) * cos(lon)
y = R * cos(lat) * sin(lon)
z = R *sin(lat)

其中R是地球的近似半径(例如6371KM)。

在newLocation.coordinate.latitude和newLocation.coordinate.longitude中,您具有所需的值,只是不进行转换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM