質問

しているのか教えてくださいはC#のコードを生成するgoogleマップ.このコードですべてのポイントでプロットを地図上にその作品の境界の矩形をしています。そしてこの範囲外にはGoogle Maps APIの設定のズームレベルを適切に表示すべてのポイントになります。

このコードはしってます。

一つのポイントによって保持されており関連付けられています。そのような場合にはその後を描いている円のポイントの半径を設定し、精度の値です。この作品は私の境界のチェックがないことをやるというたいすることができるようになります.たいていのバウンディングボックスを完了します。

このためのアルゴリズムを取る点xの計算点のyされるzメートル北xのものzメートル南のxです。

は誰でもこのアルゴリズムは、好ましくはC#.見つかの汎用アルゴリズム こちらの 私が行っていないことを正確に回答をしていて1000番台のプロセスに漂.

このは汎用例

Lat/lon given radial and distance

A point {lat,lon} is a distance d out on the tc radial from point 1 if:

     lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
     IF (cos(lat)=0)
        lon=lon1      // endpoint a pole
     ELSE
        lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
     ENDIF

これが私C#です。

  // Extend a Point North/South by the specified distance
    public static Point ExtendPoint(Point _pt, int _distance, int _bearing )
    {
        Decimal lat = 0.0;
        Decimal lng = 0.0;

        lat = Math.Asin(Math.Sin(_pt.Lat) * Math.Cos(_distance) + Math.Cos(_pt.Lat) * 
            Math.Sin(_distance) * Math.Cos(_bearing));

         if (Math.Cos(lat) == 0)
         {
            lng = _pt.Lng;      // endpoint a pole
         }
         else 
         {
             lng = (
                 (_pt.Lng - Math.Asin(Math.Sin(_bearing) * Math.Sin(_distance) / Math.Cos(lat)) 
                 + Math.PI) % (2 * Math.PI)) - Math.PI;
         }

         ret = new Point(lat,lng);
         return ret;
    }

私はこの関数を呼び出すことで、軸受の0計算の新しい北の位置の値180計算の新しい南の位置にします。

誰でもできるのでどちらかによって誤りがあったものを作アルゴリズム?

役に立ちましたか?

解決

は、所定の緯度と経度を持っている場合はそうのような緯度のXキロ変化の正確な緯度と経度を計算することができる:

new-lat = ((old-km-north + x-km-change)/40,075) * 360)
           ^ is the ratio of the                  ^ times the ratio of the circle
           of the earth the change                by 360 to get the total ratio 
           covers.                                covered in degrees.

同じことが経度に適用することができます。あなたは総距離プラスの変化を持っている場合は、同様の方法で、総度を計算することができます。

new-long = ((old-km-east + x-km-change)/40,075) * 360)
           ^ is the ratio of the                  ^ times the ratio of the circle
           of the earth the change                by 360 to get the total ratio 
           covers.                                covered in degrees.

ここでも、これらの計算は動作するはずですが、私はここに、純粋な直感をオフに実行しているんだけど、ロジックが成立しているように見えるん。

編集:(LAT)2.pi.r.cos又は40074.cosを使用して、任意の所与の緯度で地球の周囲に調節することによってSkizz 40075のニーズを指摘したように(LAT)

他のヒント

私は、コードの非常によく似た作品を持っています。別の実装と比較した場合、それは私に非常に近い結果を得ました。

私はあなたに問題があなたの代わりにラジアンで角度距離のメートル単位の直線距離として「距離」を使用していることだと思います。

/// <summary>
/// Calculates the end-point from a given source at a given range (meters) and bearing (degrees).
/// This methods uses simple geometry equations to calculate the end-point.
/// </summary>
/// <param name="source">Point of origin</param>
/// <param name="range">Range in meters</param>
/// <param name="bearing">Bearing in degrees</param>
/// <returns>End-point from the source given the desired range and bearing.</returns>
public static LatLonAlt CalculateDerivedPosition(LatLonAlt source, double range, double bearing)
{
    double latA = source.Latitude * UnitConstants.DegreesToRadians;
    double lonA = source.Longitude * UnitConstants.DegreesToRadians;
    double angularDistance = range / GeospatialConstants.EarthRadius;
    double trueCourse = bearing * UnitConstants.DegreesToRadians;

    double lat = Math.Asin(
        Math.Sin(latA) * Math.Cos(angularDistance) + 
        Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));

    double dlon = Math.Atan2(
        Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA), 
        Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));

    double lon = ((lonA + dlon + Math.PI) % UnitConstants.TwoPi) - Math.PI;

    return new LatLonAlt(
        lat * UnitConstants.RadiansToDegrees, 
        lon * UnitConstants.RadiansToDegrees, 
        source.Altitude);
}

ここで、

public const double EarthRadius = 6378137.0;   //  WGS-84 ellipsoid parameters

とLatLonAltは、度/メートル(変換が内部で行われる)です。 必要に応じて調整します。

私はあなたがUnitConstants.DegreesToRadiansの値が何であるかを把握することができますと仮定します)。

怠惰な人々、(私のような;)のために)コピー&ペーストソリューション、非常にマイナーな変更とエーリッヒMirabalのバージョン:

using System.Device.Location; // add reference to System.Device.dll
public static class GeoUtils
{
    /// <summary>
    /// Calculates the end-point from a given source at a given range (meters) and bearing (degrees).
    /// This methods uses simple geometry equations to calculate the end-point.
    /// </summary>
    /// <param name="source">Point of origin</param>
    /// <param name="range">Range in meters</param>
    /// <param name="bearing">Bearing in degrees</param>
    /// <returns>End-point from the source given the desired range and bearing.</returns>
    public static GeoCoordinate CalculateDerivedPosition(this GeoCoordinate source, double range, double bearing)
    {
        var latA = source.Latitude * DegreesToRadians;
        var lonA = source.Longitude * DegreesToRadians;
        var angularDistance = range / EarthRadius;
        var trueCourse = bearing * DegreesToRadians;

        var lat = Math.Asin(
            Math.Sin(latA) * Math.Cos(angularDistance) +
            Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));

        var dlon = Math.Atan2(
            Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA),
            Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));

        var lon = ((lonA + dlon + Math.PI) % (Math.PI*2)) - Math.PI;

        return new GeoCoordinate(
            lat * RadiansToDegrees,
            lon * RadiansToDegrees,
            source.Altitude);
    }

    private const double DegreesToRadians = Math.PI/180.0;
    private const double RadiansToDegrees = 180.0/ Math.PI;
    private const double EarthRadius = 6378137.0;
}

使用方法:

[TestClass]
public class CalculateDerivedPositionUnitTest
{
    [TestMethod]
    public void OneDegreeSquareAtEquator()
    {
        var center = new GeoCoordinate(0, 0);
        var radius = 111320;
        var southBound = center.CalculateDerivedPosition(radius, -180);
        var westBound = center.CalculateDerivedPosition(radius, -90);
        var eastBound = center.CalculateDerivedPosition(radius, 90);
        var northBound = center.CalculateDerivedPosition(radius, 0);

        Console.Write($"leftBottom: {southBound.Latitude} , {westBound.Longitude} rightTop: {northBound.Latitude} , {eastBound.Longitude}");
    }
}

私はここで何かが欠けてるかどうかわからないんだけど、私は質問は、私は緯度/経度のポイントを持っている、と私は北の点xメートルを見つけたいと南のメートル×」、と言い換えることができると思いそのポイント。 "

それが問題だ場合、あなたは(物事が簡単になります)新しい経度を見つける必要はありません、あなただけの新しい緯度を必要としています。緯度の度合いはどこでも地球上の約60海里の長さであり、海里は1852メートルです。だから、新しい緯度のXメートルの北と南のために:

north_lat = lat + x / (1852 * 60)
north_lat = min(north_lat, 90)

south_lat = lat - x / (1852 * 60)
south_lat = max(south_lat, -90)

地球を緯度の各度と正確に60海里と真球ではないので、これは完全に正確ではありません。しかし、他の回答には、緯度線は等距離であることを前提としていたので、私はあなたがそれを気にしないと仮定しています。あなたが紹介するかもしれないどのくらいの誤差に興味がある場合は、このリンクで異なる緯度のための「緯度1°変化当たりの表面までの距離」を示しウィキペディア上の素敵なテーブルがあります:

http://en.wikipedia.org/wiki/Latitude#Degree_lengthする

問題点はあるものの二つの方程式に Ed-ウィリアムというものをアサイト...のですがなかなか解析しています。

第三の方程式について 私はこちら うえます。

ここではテストケースはクリア...第三の方程式が正しいの何気誤った値をも良い。

<?php
            $lon1 = -108.553412; $lat1 = 35.467155; $linDistance = .5; $bearing = 170;
            $lon1 = deg2rad($lon1); $lat1 = deg2rad($lat1);
            $distance = $linDistance/6371;  // convert dist to angular distance in radians
            $bearing = deg2rad($bearing);

            echo "lon1: " . rad2deg($lon1) . " lat1: " . rad2deg($lat1) . "<br>\n";

// doesn't work
            $lat2 = asin(sin($lat1) * cos($distance) + cos($lat1) * sin($distance) * cos($bearing) );
            $dlon = atan2(sin($bearing) * sin($distance) * cos($lat1), cos($distance) - sin($lat1) * sin($lat2));
            $lon2 = (($lon1 - $dlon + M_PI) % (2 * M_PI)) - M_PI;  // normalise to -180...+180

            echo "lon2: " . rad2deg($lon2) . " lat2: " . rad2deg($lat2) . "<br>\n";

// same results as above
            $lat3 = asin( (sin($lat1) * cos($distance)) + (cos($lat1) * sin($distance) * cos($bearing)));
            $lon3 = (($lon1 - (asin(sin($bearing) * sin($distance) / cos($lat3))) + M_PI) % (2 * M_PI)) - M_PI;

            echo "lon3: " . rad2deg($lon3) . " lat3: " . rad2deg($lat3) . "<br>\n";

// gives correct answer... go figure
            $lat4 = asin(sin($lat1) * cos($linDistance/6371) + cos($lat1) * sin($linDistance/6371) * cos($bearing) );
            $lon4 = $lon1 + atan2( (sin($bearing) * sin($linDistance/6371) * cos($lat1) ), (cos($linDistance/6371) - sin($lat1) * sin($lat2)));

            echo "lon4: " . rad2deg($lon4) . " lat4: " . rad2deg($lat4) . "<br>\n";
?>

うに注意して認メールからの著(編"ウィリアムズ)の第二方程式:

から"実行"注意事項:

注のmodます。これで異なる方法で実行され 異なる言語、異なる条約かどうかの看板 結果は、除数は配当相当額の数値を変更しない。(またはサイン のdivisorはユークリッド.C fmodおよびJavaの%できない場合。) 本書では、Mod(y,x)で、残り分けy x常に の範囲0 <=mod < x.たとえば、次のようになります。mod(2.3ない、2)=0.3、 mod(-2.3ない、2)=1.7

また床下機能(int Excel)を返します階(x)= "最大の整数を以下のx"など階(-2.3)=-3と 階(2.3)=2

mod(y,x) = y - x*floor(y/x)

は、床下機能との関係ではないかと思われ るかどうか"int"truncatesまたは下回:

mod=y - x * int(y/x)
if ( mod < 0) mod = mod + x

phpのようなfmod Cやな"違い"です。

あなたが最初に UTMするにそれを再投影して、距離を確認する場合は、

これは、より正確です。

ホープ、このことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top