Not Getting Current Location in Tizen .Net Application

321 views Asked by At

I am trying to get location from the Tizen.Location.Locator using the GetLocation method but I'm getting the values of latitude and longitude set to 0.

I am using:

  • Visual Studio 2017
  • Emulator of Wearable 4.0
  • Have already granted the privileges for using location, also added the location feature in the manifest file.

Here's my code:

private static Locator locator = new Locator(LocationType.Gps);
try
{
    if (locator != null)
    {
        // Starts the Locator
        locator.Start();

        //Get Location
        Tizen.Location.Location currentLocation = locator.GetLocation();

        //Update xaml view
        latitudeValue.Text = currentLocation.Latitude.ToString();
        longitudeValue.Text = currentLocation.Longitude.ToString();
    }   
}
catch (InvalidOperationException exception)
{
    // Exception handling here
}

there's no description available about the variable currentLocation since it is being treated as a bool there. When I try to get the description by the quick watch feature of Visual Studio (by pressing Shift + F9), I get another error related to conversion of that bool variable

member reference base type 'bool' is not a structure or union

The above code is not showing any ServiceStateChanged event registered, but I've also included that using the way shown in the sample code, but it didn't work for me.

Now wondering about what I'm doing wrong here.

1

There are 1 answers

2
logeshpalani31 On

Your GPS most of time inactive because of battery consumption or Get location via Service provider

or

Use this Plugin to Get Current Location - https://github.com/jamesmontemagno/GeolocatorPlugin

 public async Task<Position> GetCurrentLocation()
{
   public static async Task<Position> GetCurrentPosition()
    {
            Position position = null;
            try
            {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 100;

                    position = await locator.GetLastKnownLocationAsync();

                    if (position != null)
                    {
                            //got a cahched position, so let's use it.
                            return position;
                    }

                    if (!locator.IsGeolocationAvailable || !locator.IsGeolocationEnabled)
                    {
                            //not available or enabled
                            return null;
                    }

                    position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);

            }
            catch (Exception ex)
            {
                    Debug.WriteLine("Unable to get location: " + ex);
            }

            if (position == null)
                    return null;

            var output = string.Format("Time: {0} \nLat: {1} \nLong: {2} \nAltitude: {3} \nAltitude Accuracy: {4} \nAccuracy: {5} \nHeading: {6} \nSpeed: {7}",
                    position.Timestamp, position.Latitude, position.Longitude,
                    position.Altitude, position.AltitudeAccuracy, position.Accuracy, position.Heading, position.Speed);

            Debug.WriteLine(output);

            return position;
    }
}