【发布时间】:2014-03-10 21:18:22
【问题描述】:
我已经开始在 Windows 手机应用程序中使用地图,并且已经知道如何获取当前坐标,但我不知道如何将其绘制为地图上的图钉。
这是我目前所拥有的,它调用 GetCoordinates 方法并通过单击按钮导航到地图。有谁知道我如何将坐标传递给地图并将其绘制为图钉?
private async Task GetCoordinates(string name = "My Car")
{
await Task.Run(async () =>
{
// Get the phone's current location.
Geolocator MyGeolocator = new Geolocator();
MyGeolocator.DesiredAccuracyInMeters = 5;
Geoposition MyGeoPosition = null;
try
{
MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
}
catch (Exception ex)
{
// Something else happened while acquiring the location.
MessageBox.Show(ex.Message);
}
});
}
//sets location of parking space using the GetCoordinates method
//opens map
private async void setLocationBtn_Click(object sender, RoutedEventArgs e)
{
await this.GetCoordinates();
NavigationService.Navigate(new Uri("/Maps.xaml", UriKind.Relative));
}
这是尚未做任何事情的地图类,有没有办法可以将上一个类的地理坐标传递给地图并绘制图钉?我正在考虑以某种方式在 OnNavigatedTo 方法中执行此操作:
公共部分类地图:PhoneApplicationPage { 地理定位器 geolocator = null; 布尔跟踪 = 假; 进度指标 pi; MapLayer PushpinMapLayer;
public Maps()
{
InitializeComponent();
pi = new ProgressIndicator();
pi.IsIndeterminate = true;
pi.IsVisible = false;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
}
}
【问题讨论】:
标签: c# windows-phone-8 geocode here-api pushpin