Share via


Xamarin.Forms マップの位置と距離

Xamarin.Forms.Maps 名前空間には、マップとそのピンを配置するときに通常使用する Position 構造体と、マップを配置するときに必要に応じて使用できる Distance 構造体が含まれています。

位置

Position 構造体は、緯度と経度の値として格納された位置をカプセル化します。 この構造体は、次の 2 つの読み取り専用プロパティを定義します。

  • Latitude は、位置の緯度を 10 進度で表す double 型です。
  • Longitude は、位置の軽度を 10 進度で表す double 型です。

Position オブジェクトは Position コンストラクターを使用して作成されます。このためには、緯度と経度の引数を double 値として指定する必要があります。

Position position = new Position(36.9628066, -122.0194722);

Position オブジェクトを作成する場合、緯度の値は -90.0 から 90.0 の間でクランプされ、経度の値は -180.0 から 180.0 の間でクランプされます。

Note

GeographyUtils クラスには、double の値を度からラジアンに変換する ToRadians 拡張メソッドと、double の値をラジアンから度に変換する ToDegrees 拡張メソッドがあります。

Distance

Distance 構造体は、double 値として格納された距離をカプセル化し、メートルで表されます。 この構造体は、次の 3 つの読み取り専用プロパティを定義します。

  • double 型の Kilometers は、Distance がまたがる距離をキロメートルで表します。
  • double 型の Metersは、Distance がまたがる距離をメートルで表します。
  • double 型の Miles は、Distance がまたがる距離をマイルで表します。

Distance オブジェクトは、Distance コンストラクターで生成することができ、このコンストラクターには、double で指定されたメートル引数が必要です。

Distance distance = new Distance(1450.5);

または、Distance オブジェクトは、FromKilometersFromMetersFromMilesBetweenPositions ファクトリ メソッドで作成できます。

Distance distance1 = Distance.FromKilometers(1.45); // argument represents the number of kilometers
Distance distance2 = Distance.FromMeters(1450.5);   // argument represents the number of meters
Distance distance3 = Distance.FromMiles(0.969);     // argument represents the number of miles
Distance distance4 = Distance.BetweenPositions(position1, position2);