Getting location in Windows 8 desktop apps

前端 未结 2 1032
清酒与你
清酒与你 2021-01-06 10:44

I am a total beginner at C#, but I have used Java a lot. I am trying to use the following code in my app to get location data. I am making a Windows 8 desktop app to use the

相关标签:
2条回答
  • 2021-01-06 11:01

    alex's solution works! add that reference and geolocation api starts working like a charm! so do async methods for other sensors!

    here is a function i just got working using it.

    async public void UseGeoLocation()
    {
        Geolocator _GeoLocator = new Geolocator();
        Geoposition _GeoPosition = 
            await _GeoLocator.GetGeopositionAsync();
    
        Clipboard.Clear();
        Clipboard.SetText("latitude," + 
            _GeoPosition.Coordinate.Latitude.ToString() + 
            "," + "longitude," + _GeoPosition.Coordinate.Longitude.ToString() + 
            "," + "heading," + _GeoPosition.Coordinate.Heading.ToString() +
            "," + "speed," + _GeoPosition.Coordinate.Speed.ToString());
    
        Application.Exit();
    }
    
    0 讨论(0)
  • 2021-01-06 11:10

    To fix your error you have to reference to the link that Bart gave in one of the question's comments.

    You might need to add a reference to System.Runtime.WindowsRuntime.dll as well if you are using mapped types like Windows Runtime event handlers:

    ...

    That assembly resides in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5

    I recently found a "solution" for a similar question: C# desktop application doesn't share my physical location. Maybe you might be interested by my approach: https://stackoverflow.com/a/14645837/674700.

    It's more like a workaround and it's not targeting Windows 8, but it works in the end.

    0 讨论(0)
提交回复
热议问题