尝试使用仿真器在windows phone 8中的地图元素上获取地理位置 [英] Trying to get Geolocation on a map element in windows phone 8 using emulator

查看:180
本文介绍了尝试使用仿真器在windows phone 8中的地图元素上获取地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在任何地方找到这个问题的答案,所以我认为id在这里问。基本上,Iam跟随9频道的Windows 8手机教程,为绝对的初学者。尝试遵循围绕我的应用程序教程。我在xaml中创建了一个Map元素。我创建了一个geolocator对象,并尝试将我的地图上的视图设置为当前的地理坐标。这不起作用,地图视图似乎显示每次我运行应用程序时,华盛顿州雷德蒙德的微软总部的位置。不是爱尔兰,它应该指向哪里?下面是我的代码,它包含在mainpage.xaml.cs中。

  public MainPage()
{
InitializeComponent();
Loaded + = MainPage_Loaded;


public async void MainPage_Loaded(object sender,RoutedEventArgs e)
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition position = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1),TimeSpan.FromSeconds(30));
var GeoCoorCenter =新的GeoCoordinate(position.Coordinate.Latitude,position.Coordinate.Longitude);
AroundMeMap.SetView(GeoCoorCenter,17);
}

我的代码与本教程中使用的代码相同,它似乎工作正常在那个应用程序。我也在应用清单中设置了ID_CAP_LOCATION和ID_CAP_MAP。 Iam真的不确定问题在这里。 Iam假设它与Iam在模拟器中运行应用程序有关。如果任何人都可以帮助我,那就太好了。

解决方案

我已经设法像这样运行你的代码(基于这个答案 MSDN howto ):


  • 我已经启动了模拟器,打开AdditionalTools - >位置并在地图上点击某处(作为我的位置)




  • 运行地图应用 - 我看到显示我设置的位置,关闭地图应用


  • 之后,您的应用程序应指向正确的位置



成为运行Map的错误s的应用程序修复。


I couldnt find an answer to this question anywhere so I thought id ask here. Basically Iam following along with channel 9's tutorial on windows 8 phone for absolute beginners. Trying to follow along with the 'Around me' app tutorials. I create a Map element in the xaml. I create a geolocator object and attempt to set the view on my map to my current geocordinates. This doesnt work, the map view seems to show the location of microsofts headquarters in Redmond Washington each time I run the app. not Ireland, where it should be pointing? Below is my code which is all contained in the mainpage.xaml.cs

public MainPage()
{
    InitializeComponent();
    Loaded += MainPage_Loaded;
}

public  async  void  MainPage_Loaded(object sender, RoutedEventArgs e)
{
    Geolocator geolocator = new Geolocator();
    geolocator.DesiredAccuracyInMeters = 50;
    Geoposition position = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(30));
    var GeoCoorCenter = new GeoCoordinate(position.Coordinate.Latitude,position.Coordinate.Longitude);
    AroundMeMap.SetView(GeoCoorCenter,17);
}

my code is the same as that used in the tutorial and it seems to work in that app. I also have the ID_CAP_LOCATION and ID_CAP_MAP set in the app manifest. Iam really not sure what the issue is here. Iam assuming its got something to do with the fact that Iam running the application in the emulator. If anyone can help me that would be great.

解决方案

I've managed to run your code like this (basing on this answer and MSDN howto):

  • I've started the emulator, opened AdditionalTools -> Location and clicked somewhere on the Map (as my Location)

  • run Maps App - I see that shows the Location I've set, Close the Maps App

  • after that your App should point the right Location

As it's written at MSDN - it seems to be a bug which running Maps App fixes.

这篇关于尝试使用仿真器在windows phone 8中的地图元素上获取地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆