mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Add measurement line to sample apps
This commit is contained in:
parent
365fdb75dc
commit
e1c6bfdf9c
|
|
@ -100,12 +100,18 @@
|
||||||
|
|
||||||
<map:Map x:Name="map" ManipulationMode="All"
|
<map:Map x:Name="map" ManipulationMode="All"
|
||||||
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
|
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
|
||||||
|
PointerPressed="MapPointerPressed"
|
||||||
|
PointerReleased="MapPointerReleased"
|
||||||
PointerMoved="MapPointerMoved"
|
PointerMoved="MapPointerMoved"
|
||||||
PointerExited="MapPointerExited">
|
PointerExited="MapPointerExited">
|
||||||
<map:Map.Center>
|
<map:Map.Center>
|
||||||
<map:Location Latitude="53.5" Longitude="8.2"/>
|
<map:Location Latitude="53.5" Longitude="8.2"/>
|
||||||
</map:Map.Center>
|
</map:Map.Center>
|
||||||
|
|
||||||
|
<map:MapPolyline x:Name="measurementLine" Visibility="Collapsed"
|
||||||
|
Stroke="{Binding Foreground, ElementName=map}"
|
||||||
|
StrokeThickness="2" StrokeDashArray="1,1"/>
|
||||||
|
|
||||||
<map:MapItemsControl ItemsSource="{Binding Polylines}"
|
<map:MapItemsControl ItemsSource="{Binding Polylines}"
|
||||||
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
|
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
using MapControl;
|
using MapControl;
|
||||||
using MapControl.UiTools;
|
using MapControl.UiTools;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Windows.Devices.Input;
|
||||||
|
using Windows.System;
|
||||||
using Windows.UI;
|
using Windows.UI;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
|
@ -83,34 +87,52 @@ namespace SampleApplication
|
||||||
map.TargetHeading = 0d;
|
map.TargetHeading = 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void MapPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
||||||
|
{
|
||||||
|
var point = e.GetCurrentPoint(map);
|
||||||
|
|
||||||
|
if (point.Properties.IsRightButtonPressed)
|
||||||
|
{
|
||||||
|
var location = map.ViewToLocation(point.Position);
|
||||||
|
|
||||||
|
if (location != null)
|
||||||
|
{
|
||||||
|
measurementLine.Visibility = Visibility.Visible;
|
||||||
|
measurementLine.Locations = new LocationCollection(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) &&
|
||||||
|
map.MapLayer is WmsImageLayer wmsLayer)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(point.Position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MapPointerReleased(object sender, PointerRoutedEventArgs e)
|
||||||
|
{
|
||||||
|
measurementLine.Visibility = Visibility.Collapsed;
|
||||||
|
measurementLine.Locations = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void MapPointerMoved(object sender, PointerRoutedEventArgs e)
|
private void MapPointerMoved(object sender, PointerRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var location = map.ViewToLocation(e.GetCurrentPoint(map).Position);
|
var location = map.ViewToLocation(e.GetCurrentPoint(map).Position);
|
||||||
|
|
||||||
if (location != null)
|
if (location != null)
|
||||||
{
|
{
|
||||||
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
|
||||||
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
|
||||||
var latHemisphere = 'N';
|
|
||||||
var lonHemisphere = 'E';
|
|
||||||
|
|
||||||
if (latitude < 0)
|
|
||||||
{
|
|
||||||
latitude = -latitude;
|
|
||||||
latHemisphere = 'S';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (longitude < 0)
|
|
||||||
{
|
|
||||||
longitude = -longitude;
|
|
||||||
lonHemisphere = 'W';
|
|
||||||
}
|
|
||||||
|
|
||||||
mouseLocation.Text = string.Format(CultureInfo.InvariantCulture,
|
|
||||||
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
|
||||||
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
|
||||||
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
|
||||||
mouseLocation.Visibility = Visibility.Visible;
|
mouseLocation.Visibility = Visibility.Visible;
|
||||||
|
mouseLocation.Text = GetLatLonText(location);
|
||||||
|
|
||||||
|
var start = measurementLine.Locations?.FirstOrDefault();
|
||||||
|
|
||||||
|
if (start != null)
|
||||||
|
{
|
||||||
|
measurementLine.Locations = LocationCollection.OrthodromeLocations(start, location);
|
||||||
|
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -124,5 +146,45 @@ namespace SampleApplication
|
||||||
mouseLocation.Visibility = Visibility.Collapsed;
|
mouseLocation.Visibility = Visibility.Collapsed;
|
||||||
mouseLocation.Text = string.Empty;
|
mouseLocation.Text = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetLatLonText(Location location)
|
||||||
|
{
|
||||||
|
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
||||||
|
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
||||||
|
var latHemisphere = 'N';
|
||||||
|
var lonHemisphere = 'E';
|
||||||
|
|
||||||
|
if (latitude < 0)
|
||||||
|
{
|
||||||
|
latitude = -latitude;
|
||||||
|
latHemisphere = 'S';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longitude < 0)
|
||||||
|
{
|
||||||
|
longitude = -longitude;
|
||||||
|
lonHemisphere = 'W';
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
||||||
|
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
||||||
|
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDistanceText(double distance)
|
||||||
|
{
|
||||||
|
var unit = "m";
|
||||||
|
|
||||||
|
if (distance >= 1000d)
|
||||||
|
{
|
||||||
|
distance /= 1000d;
|
||||||
|
unit = "km";
|
||||||
|
}
|
||||||
|
|
||||||
|
var distanceFormat = distance >= 100d ? "F0" : "F1";
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, "\n {0:" + distanceFormat + "} {1}", distance, unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,12 +108,17 @@
|
||||||
<map:Map x:Name="map" ManipulationMode="All"
|
<map:Map x:Name="map" ManipulationMode="All"
|
||||||
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
|
MinZoomLevel="2" MaxZoomLevel="21" ZoomLevel="11"
|
||||||
PointerPressed="MapPointerPressed"
|
PointerPressed="MapPointerPressed"
|
||||||
|
PointerReleased="MapPointerReleased"
|
||||||
PointerMoved="MapPointerMoved"
|
PointerMoved="MapPointerMoved"
|
||||||
PointerExited="MapPointerExited">
|
PointerExited="MapPointerExited">
|
||||||
<map:Map.Center>
|
<map:Map.Center>
|
||||||
<map:Location Latitude="53.5" Longitude="8.2"/>
|
<map:Location Latitude="53.5" Longitude="8.2"/>
|
||||||
</map:Map.Center>
|
</map:Map.Center>
|
||||||
|
|
||||||
|
<map:MapPolyline x:Name="measurementLine" Visibility="Collapsed"
|
||||||
|
Stroke="{Binding Foreground, ElementName=map}"
|
||||||
|
StrokeThickness="2" StrokeDashArray="1,1"/>
|
||||||
|
|
||||||
<map:MapItemsControl ItemsSource="{Binding Polylines}"
|
<map:MapItemsControl ItemsSource="{Binding Polylines}"
|
||||||
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
|
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Windows.System;
|
||||||
|
|
||||||
namespace SampleApplication
|
namespace SampleApplication
|
||||||
{
|
{
|
||||||
|
|
@ -104,46 +106,51 @@ namespace SampleApplication
|
||||||
|
|
||||||
private async void MapPointerPressed(object sender, PointerRoutedEventArgs e)
|
private async void MapPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (map.MapLayer is WmsImageLayer wmsLayer &&
|
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
||||||
e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
|
||||||
{
|
{
|
||||||
PointerPoint point = e.GetCurrentPoint(map);
|
var point = e.GetCurrentPoint(map);
|
||||||
|
|
||||||
if (point.Properties.IsRightButtonPressed)
|
if (point.Properties.IsRightButtonPressed)
|
||||||
|
{
|
||||||
|
var location = map.ViewToLocation(point.Position);
|
||||||
|
|
||||||
|
if (location != null)
|
||||||
|
{
|
||||||
|
measurementLine.Visibility = Visibility.Visible;
|
||||||
|
measurementLine.Locations = new LocationCollection(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) &&
|
||||||
|
map.MapLayer is WmsImageLayer wmsLayer)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(point.Position));
|
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(point.Position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapPointerReleased(object sender, PointerRoutedEventArgs e)
|
||||||
|
{
|
||||||
|
measurementLine.Visibility = Visibility.Collapsed;
|
||||||
|
measurementLine.Locations = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void MapPointerMoved(object sender, PointerRoutedEventArgs e)
|
private void MapPointerMoved(object sender, PointerRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var location = map.ViewToLocation(e.GetCurrentPoint(map).Position);
|
var point = e.GetCurrentPoint(map);
|
||||||
|
var location = map.ViewToLocation(point.Position);
|
||||||
|
|
||||||
if (location != null)
|
if (location != null)
|
||||||
{
|
{
|
||||||
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
|
||||||
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
|
||||||
var latHemisphere = 'N';
|
|
||||||
var lonHemisphere = 'E';
|
|
||||||
|
|
||||||
if (latitude < 0)
|
|
||||||
{
|
|
||||||
latitude = -latitude;
|
|
||||||
latHemisphere = 'S';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (longitude < 0)
|
|
||||||
{
|
|
||||||
longitude = -longitude;
|
|
||||||
lonHemisphere = 'W';
|
|
||||||
}
|
|
||||||
|
|
||||||
mouseLocation.Text = string.Format(CultureInfo.InvariantCulture,
|
|
||||||
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
|
||||||
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
|
||||||
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
|
||||||
mouseLocation.Visibility = Visibility.Visible;
|
mouseLocation.Visibility = Visibility.Visible;
|
||||||
|
mouseLocation.Text = GetLatLonText(location);
|
||||||
|
|
||||||
|
var start = measurementLine.Locations?.FirstOrDefault();
|
||||||
|
|
||||||
|
if (start != null)
|
||||||
|
{
|
||||||
|
measurementLine.Locations = LocationCollection.OrthodromeLocations(start, location);
|
||||||
|
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -157,5 +164,45 @@ namespace SampleApplication
|
||||||
mouseLocation.Visibility = Visibility.Collapsed;
|
mouseLocation.Visibility = Visibility.Collapsed;
|
||||||
mouseLocation.Text = string.Empty;
|
mouseLocation.Text = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetLatLonText(Location location)
|
||||||
|
{
|
||||||
|
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
||||||
|
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
||||||
|
var latHemisphere = 'N';
|
||||||
|
var lonHemisphere = 'E';
|
||||||
|
|
||||||
|
if (latitude < 0)
|
||||||
|
{
|
||||||
|
latitude = -latitude;
|
||||||
|
latHemisphere = 'S';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longitude < 0)
|
||||||
|
{
|
||||||
|
longitude = -longitude;
|
||||||
|
lonHemisphere = 'W';
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
||||||
|
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
||||||
|
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDistanceText(double distance)
|
||||||
|
{
|
||||||
|
var unit = "m";
|
||||||
|
|
||||||
|
if (distance >= 1000d)
|
||||||
|
{
|
||||||
|
distance /= 1000d;
|
||||||
|
unit = "km";
|
||||||
|
}
|
||||||
|
|
||||||
|
var distanceFormat = distance >= 100d ? "F0" : "F1";
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, "\n {0:" + distanceFormat + "} {1}", distance, unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,9 +117,15 @@
|
||||||
Center="53.5,8.2" ManipulationMode="All"
|
Center="53.5,8.2" ManipulationMode="All"
|
||||||
MouseLeftButtonDown="MapMouseLeftButtonDown"
|
MouseLeftButtonDown="MapMouseLeftButtonDown"
|
||||||
MouseRightButtonDown="MapMouseRightButtonDown"
|
MouseRightButtonDown="MapMouseRightButtonDown"
|
||||||
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave"
|
MouseRightButtonUp="MapMouseRightButtonUp"
|
||||||
|
MouseMove="MapMouseMove"
|
||||||
|
MouseLeave="MapMouseLeave"
|
||||||
ManipulationInertiaStarting="MapManipulationInertiaStarting">
|
ManipulationInertiaStarting="MapManipulationInertiaStarting">
|
||||||
|
|
||||||
|
<map:MapPolyline x:Name="measurementLine" Visibility="Collapsed"
|
||||||
|
Stroke="{Binding Foreground, ElementName=map}"
|
||||||
|
StrokeThickness="2" StrokeDashArray="1,1"/>
|
||||||
|
|
||||||
<map:MapItemsControl ItemsSource="{Binding Polylines}"/>
|
<map:MapItemsControl ItemsSource="{Binding Polylines}"/>
|
||||||
|
|
||||||
<map:MapItemsControl ItemsSource="{Binding Points}"
|
<map:MapItemsControl ItemsSource="{Binding Points}"
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
using MapControl.Caching;
|
using MapControl.Caching;
|
||||||
using MapControl.UiTools;
|
using MapControl.UiTools;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
@ -74,50 +76,52 @@ namespace SampleApplication
|
||||||
map.TargetHeading = 0d;
|
map.TargetHeading = 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
private async void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.ClickCount == 2)
|
if (e.ClickCount == 2)
|
||||||
{
|
{
|
||||||
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
|
||||||
}
|
}
|
||||||
|
else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) &&
|
||||||
|
map.MapLayer is WmsImageLayer wmsLayer)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(e.GetPosition(map)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void MapMouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
private void MapMouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (map.MapLayer is WmsImageLayer wmsLayer)
|
var location = map.ViewToLocation(e.GetPosition(map));
|
||||||
|
|
||||||
|
if (location != null)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(e.GetPosition(map)));
|
measurementLine.Visibility = Visibility.Visible;
|
||||||
|
measurementLine.Locations = new LocationCollection(location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MapMouseRightButtonUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
measurementLine.Visibility = Visibility.Collapsed;
|
||||||
|
measurementLine.Locations = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void MapMouseMove(object sender, MouseEventArgs e)
|
private void MapMouseMove(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
var location = map.ViewToLocation(e.GetPosition(map));
|
var location = map.ViewToLocation(e.GetPosition(map));
|
||||||
|
|
||||||
if (location != null)
|
if (location != null)
|
||||||
{
|
{
|
||||||
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
|
||||||
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
|
||||||
var latHemisphere = 'N';
|
|
||||||
var lonHemisphere = 'E';
|
|
||||||
|
|
||||||
if (latitude < 0)
|
|
||||||
{
|
|
||||||
latitude = -latitude;
|
|
||||||
latHemisphere = 'S';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (longitude < 0)
|
|
||||||
{
|
|
||||||
longitude = -longitude;
|
|
||||||
lonHemisphere = 'W';
|
|
||||||
}
|
|
||||||
|
|
||||||
mouseLocation.Text = string.Format(CultureInfo.InvariantCulture,
|
|
||||||
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
|
||||||
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
|
||||||
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
|
||||||
mouseLocation.Visibility = Visibility.Visible;
|
mouseLocation.Visibility = Visibility.Visible;
|
||||||
|
mouseLocation.Text = GetLatLonText(location);
|
||||||
|
|
||||||
|
var start = measurementLine.Locations?.FirstOrDefault();
|
||||||
|
|
||||||
|
if (start != null)
|
||||||
|
{
|
||||||
|
measurementLine.Locations = LocationCollection.OrthodromeLocations(start, location);
|
||||||
|
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -143,5 +147,45 @@ namespace SampleApplication
|
||||||
mapItem.IsSelected = !mapItem.IsSelected;
|
mapItem.IsSelected = !mapItem.IsSelected;
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetLatLonText(Location location)
|
||||||
|
{
|
||||||
|
var latitude = (int)Math.Round(location.Latitude * 60000d);
|
||||||
|
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
|
||||||
|
var latHemisphere = 'N';
|
||||||
|
var lonHemisphere = 'E';
|
||||||
|
|
||||||
|
if (latitude < 0)
|
||||||
|
{
|
||||||
|
latitude = -latitude;
|
||||||
|
latHemisphere = 'S';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (longitude < 0)
|
||||||
|
{
|
||||||
|
longitude = -longitude;
|
||||||
|
lonHemisphere = 'W';
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture,
|
||||||
|
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
||||||
|
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
||||||
|
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDistanceText(double distance)
|
||||||
|
{
|
||||||
|
var unit = "m";
|
||||||
|
|
||||||
|
if (distance >= 1000d)
|
||||||
|
{
|
||||||
|
distance /= 1000d;
|
||||||
|
unit = "km";
|
||||||
|
}
|
||||||
|
|
||||||
|
var distanceFormat = distance >= 100d ? "F0" : "F1";
|
||||||
|
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, "\n {0:" + distanceFormat + "} {1}", distance, unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue