问题
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