locked
Incorrect countrycode,and posistion being returned by Geolocator.GetGeopositionAsync() function.

    Question

  • Hi Everyone

    We are facing an issue in retrieval of position of a user from the windows 8 modern app. Though my pc is physically located in India, the following code is returning US.

        Geolocator geo = new Geolocator();

                                    CancellationTokenSource cts = new CancellationTokenSource();

                                    CancellationToken token = cts.Token;

                                    Geoposition pos = await geo.GetGeopositionAsync();

                                    string country = pos.CivicAddress.Country.ToString().ToLower();

                                                         double Latitude = pos.Coordinate.Latitude;

                                  double Longitude = pos.Coordinate.Longitude;

    What we were able to confirm is the country, co-ordinates being returned is actually not based on the actual physical location, but the one available in 'Location' of 'Region' in Control Panel. Is this expected behaviour of GetGeopositionAsync()? Any possible way to avoid this problem, and retrieve the actual physical position of the user/device?

    Another weird thing is that System.Device.Location.GeoCoordinateWatcher(),  which is supported in console applications is fact returning the actual physical location. The code in the console app is as below.

                var watcher = new System.Device.Location.GeoCoordinateWatcher(); 
                watcher.TryStart(false, TimeSpan.FromMilliseconds(100000)); string status = ""; 
                GeoCoordinate coord = watcher.Position.Location; 
                if (coord.IsUnknown != true) 
                { 
                    Console.WriteLine(String.Format("Received GPS location: {0}, {1}", coord.Latitude, coord.Longitude)); 
                }

    Any insights on to why this difference between the two functions? From what I've read, they both are supposed to be similar.

    Wednesday, February 25, 2015 1:09 PM

All replies

  • I'll ask about this.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, February 26, 2015 1:12 PM
    Moderator