我正在开发一个应该在Android或IOS上打开地图的应用程序。我面临的问题(在Android上,IOS仍未测试)是它打开地图,总是在同一位置,似乎是我的位置,而不是定义的位置。这是我的代码......
public MainPage()
{
InitializeComponent();
storesList.BackgroundColor = Color.CornflowerBlue;
storesList.SeparatorColor=Color.White;
storesList.ItemSelected += CellSelected;
storesList.ItemTemplate = new DataTemplate(() =>
{
var storeCell = new StoreCell();
storeCell.SetBinding(StoreCell.NameProperty, "Name");
storeCell.SetBinding(StoreCell.LocationProperty, "Location");
storeCell.SetBinding(StoreCell.ScheduleProperty, "Schedule");
return storeCell;
});
Stores = new ObservableCollection<Store>();
Store store1 = new Store
{
Name = "Pombal",
Location = new Coordinate(39.9143958, -8.6297282).ToString()
};
Store store2 = new Store
{
Name = "Unknown",
Location = new Coordinate(39.7301803, -8.8438668).ToString(),
Schedule = "09:00-12:30 / 13:30-18:00"
};
Stores.Add(store1);
Stores.Add(store2);
Stores.Add(store1);
Stores.Add(store2);
Stores.Add(store1);
Stores.Add(store2);
Stores.Add(store1);
Stores.Add(store2);
storesList.ItemsSource = Stores;
}
void CellSelected(object sender, SelectedItemChangedEventArgs e)
{
var address = ((Store)e.SelectedItem).Location.Replace(" ", "");
//storesList.SelectedItem = null;
Uri uri;
switch (Device.RuntimePlatform)
{
case Device.iOS:
uri = new Uri(string.Format("http://maps.apple.com/?q={0}", address));
System.Diagnostics.Debug.WriteLine(uri);
Device.OpenUri(uri);
break;
case Device.Android:
uri = new Uri("geo:" + address);
System.Diagnostics.Debug.WriteLine(uri);
Device.OpenUri(uri);
break;
}
}
此外,如果你可以帮我,列表的项目不是取消选择我在哪里放置这个storesList.SelectedItem = null;
,以便当我回到我的应用程序时,我可以选择与我之前相同的项目(它不工作我拥有它,我得到空引用异常)