亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

計算遠離一個坐標的新坐標x米和y度

計算遠離一個坐標的新坐標x米和y度

iOS
幕布斯7119047 2019-12-15 12:08:55
我一定在文檔中缺少東西,我認為這應該很容易...如果我有一個坐標,并且想在某個方向上x米外獲得一個新坐標。我該怎么做呢?我正在尋找類似的東西-(CLLocationCoordinate2D) translateCoordinate:(CLLocationCoordinate2D)coordinate                                translateMeters:(int)meters                               translateDegrees:(double)degrees;謝謝!
查看完整描述

3 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

不幸的是,API中沒有提供此類功能,因此您必須編寫自己的函數。


該站點提供了一些涉及緯度/經度的計算以及示例JavaScript代碼。具體來說,標題為“給定距離和起點的目標點”的部分顯示了如何計算您的要求。


JavaScript代碼在該頁面的底部,這是將其轉換為Objective-C的一種可能方法:


- (double)radiansFromDegrees:(double)degrees

{

    return degrees * (M_PI/180.0);    

}


- (double)degreesFromRadians:(double)radians

{

    return radians * (180.0/M_PI);

}


- (CLLocationCoordinate2D)coordinateFromCoord:

        (CLLocationCoordinate2D)fromCoord 

        atDistanceKm:(double)distanceKm 

        atBearingDegrees:(double)bearingDegrees

{

    double distanceRadians = distanceKm / 6371.0;

      //6,371 = Earth's radius in km

    double bearingRadians = [self radiansFromDegrees:bearingDegrees];

    double fromLatRadians = [self radiansFromDegrees:fromCoord.latitude];

    double fromLonRadians = [self radiansFromDegrees:fromCoord.longitude];


    double toLatRadians = asin( sin(fromLatRadians) * cos(distanceRadians) 

        + cos(fromLatRadians) * sin(distanceRadians) * cos(bearingRadians) );


    double toLonRadians = fromLonRadians + atan2(sin(bearingRadians) 

        * sin(distanceRadians) * cos(fromLatRadians), cos(distanceRadians) 

        - sin(fromLatRadians) * sin(toLatRadians));


    // adjust toLonRadians to be in the range -180 to +180...

    toLonRadians = fmod((toLonRadians + 3*M_PI), (2*M_PI)) - M_PI;


    CLLocationCoordinate2D result;

    result.latitude = [self degreesFromRadians:toLatRadians];

    result.longitude = [self degreesFromRadians:toLonRadians];

    return result;

}

在JS代碼中,它包含此鏈接,該鏈接顯示了對大于地球周長1/4的距離的更精確的計算。


另請注意,上面的代碼接受以km為單位的距離,因此請確保在通過之前將米除以1000.0。



查看完整回答
反對 回復 2019-12-16
?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

我找到了一種方法,必須進行挖掘以找到正確的結構和功能。我最終沒有使用度數,而是用經度和緯度來表示米。


這是我的操作方式:


-(CLLocationCoordinate2D)translateCoord:(CLLocationCoordinate2D)coord MetersLat:(double)metersLat MetersLong:(double)metersLong{


    CLLocationCoordinate2D tempCoord;


    MKCoordinateRegion tempRegion = MKCoordinateRegionMakeWithDistance(coord, metersLat, metersLong);

    MKCoordinateSpan tempSpan = tempRegion.span;


    tempCoord.latitude = coord.latitude + tempSpan.latitudeDelta;

    tempCoord.longitude = coord.longitude + tempSpan.longitudeDelta;


    return tempCoord;


}

當然,如果將來我真的需要使用學位,對我進行一些更改(如我所想)很容易(我認為...)。



查看完整回答
反對 回復 2019-12-16
?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

使用an MKCoordinateRegion存在一些問題-可以調整返回的區域以適合該位置,因為兩個增量可能無法準確地映射到該緯度處的投影,如果您希望其中一個軸的零增量不符合要求,等等。


此功能用于MKMapPoint執行坐標平移,使您可以在地圖投影的坐標空間中移動點,然后從中提取坐標。


CLLocationCoordinate2D MKCoordinateOffsetFromCoordinate(CLLocationCoordinate2D coordinate, CLLocationDistance offsetLatMeters, CLLocationDistance offsetLongMeters) {

    MKMapPoint offsetPoint = MKMapPointForCoordinate(coordinate);


    CLLocationDistance metersPerPoint = MKMetersPerMapPointAtLatitude(coordinate.latitude);

    double latPoints = offsetLatMeters / metersPerPoint;

    offsetPoint.y += latPoints;

    double longPoints = offsetLongMeters / metersPerPoint;

    offsetPoint.x += longPoints;


    CLLocationCoordinate2D offsetCoordinate = MKCoordinateForMapPoint(offsetPoint);

    return offsetCoordinate;

}



查看完整回答
反對 回復 2019-12-16
  • 3 回答
  • 0 關注
  • 425 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號