在 windows phone 8.1 中打开本机地图应用程序,中心到特定点
Open native maps app in windows phone 8.1 with center to specific point
我想通过单击按钮启动地图应用程序并将视图居中到特定点。在 JSON 文件中,我有很多项目,每个项目都有纬度和经度 属性。我想将地图以这些属性为中心。我可以这样启动应用程序
private async void Button_Click(object sender, RoutedEventArgs e)
{
string uriToLaunch = "bingmaps:?cp=40.726966~-74.006076&lvl=10";
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}
但是我如何用我的纬度和经度属性替换例如 40.726966 和 -74.006076?
我试过这个
private async void Button_Click(object sender, RoutedEventArgs e)
{
SampleDataItem item;
string uriToLaunch = "bingmaps:?cp="+item.Latitude+"~"+item.Longitude+"&lvl=10";
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}
我得到一个使用未分配变量项的异常。关于如何进行这项工作的任何线索?
如果您的按钮用于列表中的每个项目,或者按钮应该具有数据上下文,以便它可以获取用于显示地图的项目,或者您可以手动为项目变量赋值。那么你的代码应该是
private async void Button_Click(object sender, RoutedEventArgs e)
{
SampleDataItem item=(sender as Button).DataContext as SampleDataItem;
if(item!=null){
string uriToLaunch = string.Format("bingmaps:?cp={0}~{1}&lvl=20&collection=point.{2}_{3}_{4}", context.latitude, context.longitude, context.latitude, context.longitude, title);
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}}
错误是因为item变量没有赋值,需要通过DataContext或直接赋值。
我想通过单击按钮启动地图应用程序并将视图居中到特定点。在 JSON 文件中,我有很多项目,每个项目都有纬度和经度 属性。我想将地图以这些属性为中心。我可以这样启动应用程序
private async void Button_Click(object sender, RoutedEventArgs e)
{
string uriToLaunch = "bingmaps:?cp=40.726966~-74.006076&lvl=10";
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}
但是我如何用我的纬度和经度属性替换例如 40.726966 和 -74.006076? 我试过这个
private async void Button_Click(object sender, RoutedEventArgs e)
{
SampleDataItem item;
string uriToLaunch = "bingmaps:?cp="+item.Latitude+"~"+item.Longitude+"&lvl=10";
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}
我得到一个使用未分配变量项的异常。关于如何进行这项工作的任何线索?
如果您的按钮用于列表中的每个项目,或者按钮应该具有数据上下文,以便它可以获取用于显示地图的项目,或者您可以手动为项目变量赋值。那么你的代码应该是
private async void Button_Click(object sender, RoutedEventArgs e)
{
SampleDataItem item=(sender as Button).DataContext as SampleDataItem;
if(item!=null){
string uriToLaunch = string.Format("bingmaps:?cp={0}~{1}&lvl=20&collection=point.{2}_{3}_{4}", context.latitude, context.longitude, context.latitude, context.longitude, title);
var uri = new Uri(uriToLaunch);
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
}}
错误是因为item变量没有赋值,需要通过DataContext或直接赋值。