Geolocation in C#

后端 未结 3 1279
难免孤独
难免孤独 2021-02-13 18:49

I\'m trying to develop an application that should be something like a game. The user would have some locations in a city and he would have to do something on each location. In o

相关标签:
3条回答
  • 2021-02-13 19:29

    At least for me the code is working ok, And I get to "txt.Text = "KONT" Where are you finding you constant latitude or longitude?

    0 讨论(0)
  • 2021-02-13 19:30

    try this:

    Geolocator.DesiredAccuracy = PositionAccuracy.High;
    
    0 讨论(0)
  • 2021-02-13 19:40

    I think that the problem occurs, because you give too little time for Geolocator to make a proper readout with Geolocator.GetGeopositionAsync - timeout:

    Geoposition geoposition = await geolocator.GetGeopositionAsync(TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1));
    

    You give it only 1 second, while getting more accurate position takes time.

    My example:

    Geolocator geolocator;
    Geoposition geoposition;
    public MainPage()
    {
       this.InitializeComponent();
       geolocator = new Geolocator();
       geolocator.DesiredAccuracyInMeters = 10;
       geolocator.ReportInterval = 0;
    
       myButton.Click += async (sender, e) =>
           {
               geoposition = await geolocator.GetGeopositionAsync();
               string latitude = geoposition.Coordinate.Latitude.ToString("0.0000000000");
               string Longitude = geoposition.Coordinate.Longitude.ToString("0.0000000000");
               string Accuracy = geoposition.Coordinate.Accuracy.ToString("0.0000000000");
           };
    }
    

    The code above returs a position (in my case) with accuracy of ~35 meters, BUT after waiting about 20-30 seconds. Note also that accuracy depends on numer of available sattelites.

    Also some remarks from MSDN:

    1. set Geolocator.ReportInterval to 0:

      Apps that do require real-time data should set ReportInterval to 0, to indicate that no minimum interval is specified. On Windows, when the report interval is 0, the app receives events at the frequency that the most accurate location source sends them. On Windows Phone, the app will receive updates at a rate dependent on the accuracy requested by the app.

    2. set Geolocator.DesiredAccuracyInMeters to 10 meters:

      ◾If the user is trying to share his position, the app should request an accuracy of about 10 meters.

    3. try to dealy between starting Geolocator and reding it:

      Consider start-up delay. The first time an app requests location data, there might be a short delay (1-2 seconds) while the location provider starts up. Consider this in the design of your app's UI. For instance, you may want to avoid blocking other tasks pending the completion of the call to GetGeopositionAsync.

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