Trying to get Geolocation on a map element in windows phone 8 using emulator

随声附和 提交于 2019-12-14 03:03:22

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21659312/trying-to-get-geolocation-on-a-map-element-in-windows-phone-8-using-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!