0
我正在構建一個讀取文件(其中包含GPS點,每個點包含經緯度字段)的windows phone 8.1應用程序。對於每一個點我都有,所以它在地圖控件上顯示一個小圖釘圖標,基於它從上面的文件進行協調。我希望可以點擊圖釘,最終目標是獲取用戶點擊的緯度和經度,並根據點擊哪個點來執行適當的操作。我怎樣才能掌握這些信息?這是我試過,但它不工作:獲取有關哪個推針被點擊的信息
private async void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
var point = sender as Geopoint;
MessageDialog msgbox = new MessageDialog("point tapped: " + point.Position.Latitude);
await msgbox.ShowAsync();
}
這是我的模板:
<Maps:MapControl x:Name="myMap">
<Maps:MapItemsControl ItemsSource="{Binding }">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="Assets/pushpin.png" Tapped="Image_Tapped" Width="50" Height="50" Maps:MapControl.Location="{Binding}"></Image>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
</Maps:MapControl>
這是我用什麼來讀取文件並顯示圖釘(它顯示他們罰款)
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
Geoposition position = await App.DataModel.GetCurrentPosition();
await myMap.TrySetViewAsync(position.Coordinate.Point, 16D);
List<Geopoint> list = new List<Geopoint>();
bool exist; // used to check if JSON file exists
exist = await App.DataModel.FileExistsAsync();
if (exist == true)
{
// read the file and load points into a list
await App.DataModel.ReadFile();
foreach (var point in App.DataModel.notes)
{
Geopoint geo = new Geopoint(new BasicGeoposition()
{
Latitude = point.Latitude,
Longitude = point.Longitude
});
list.Add(geo);
}
}
myMap.DataContext = list;
}