Languages

Menu
Sites
Language
Exception thrown when getting Location from Tizen.Locator

I am trying to get location from the Tizen.Location.Locator using the GetLocation method but I'm getting an exception. The weird part is that when I catch the exception in the catch block of the code, there's no description available about the exception since it is being treated as a "bool" by the IDE and when I try to get the description by myException.Message property in the catch block, of course I get another error related to conversion of that bool variable (member reference base type 'bool' is not a structure or union). When I tried catching all exceptions (related to the method) in separate blocks, it showed that there's an InvalidOperationException. It may look weird but the exception is being shown as a "bool" variable in the catch block.

I am using: 

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

Here's my code:

private static GpsSatellite gpsSatellite = new GpsSatellite(locator);
private static Locator locator = new Locator(LocationType.Gps);
try
{
    if (locator != null)
    {
        // Starts the Locator
        locator.Start();
    
        //Get Location
        Location currentLocation = locator.GetLocation(); // Exception thrown from here
        locationAccessModel.ErrorMessage = "";
    
        //Update View
        latitudeValue.Text = locationAccessModel.CurrentLocation.Latitude.ToString();
        longitudeValue.Text = locationAccessModel.CurrentLocation.Longitude.ToString();
    }   
    
}
catch (InvalidOperationException exception)
{
    // Exception handling
    locationAccessModel.ErrorMessage = exception.Message;

    // Update View
}

 

The above code is not showing any ServiceStateChanged event registered, but I've also tried that before the locator.Start() method, but got no luck.

Have spent so many time but couldn't figure out what I'm doing wrong.

Edited by: Itban Saeed on 03 Aug, 2019

Responses

9 Replies
Tizen .NET

Hi Itban Saeed,

First of all, please check if you get user's permission to use location information. (app user’s permission must be granted to use privacy-related functionality.) After then, you can use Location API.

https://developer.tizen.org/development/guides/.net-application/security/privacy-related-permissions

The list of privacy-related privileges

 

 

Tizen .NET

Regarding error description, it will be improved. Thank you for sharing your issue with us.

 

Tizen .NET

Now I found an issue in your code.

Without user permission, "UnauthorizedAccessException" occurs.  You better use "Exception" instead of "InvalidOperationException".

Itban Saeed

I used the Exception, but the occured exception was not being caught in there, so when I set separate catch blocks for the possible exceptions, the exception was caught in the InvalidOperationException, the code worked with a hit n trial approach, it was giving the values of latitude and longitude as 0 but when I reopened the project now, I'm still getting the same InvalidOperationException. I've reviewed the list of privacy privileges and there are only two privileges that I'm using (helthinfo and location) since both are public level privileges so there shouldn't be any issue. Is there anything else that I should check?

Itban Saeed

So I've found a mistake, I didn't know about injecting the location values in emulator control panel first. Now I'm trying to inject the values but I'm facing an error (posted by someone else on SO: https://stackoverflow.com/questions/55435725/cant-inject-location-using-tizen-emulator-wearable) but in my case the Map is also not loaded, there's just a search bar instead of maps so when I try to inject the location manually the dialog box hangs and does nothing untill I cancel the inject process.

Tizen .NET

Hi Itban Saeed,
Even though the UI seems to hang but it's actually set, so you can test GetLocation API().
It is same as manual setting. the value will be returned as you set.
To avoid this confusion, we will consider to improve our tools.
Thank you.

Itban Saeed

Many thanks for the response. I'm wondering if there are any location related privileges to be added other then the ones mentioned on this page (https://developer.tizen.org/development/guides/.net-application/location-and-sensors/location-information#start) ? 

I've updated the code and removed the first line of the above code. 

Now I'm getting the values of latitude and longitude set to 0. In the quick watch feature, 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

I've followed the methods shown on the official page here (https://developer.tizen.org/development/guides/.net-application/location-and-sensors/location-information#start) may be I'm missing any other references ?

Tizen .NET

It seems that there's a problem in debugger.
Wrong type is returned when the variable is in if-statement.
I've been reported to Tizen SDK team. and I'll share it as soon as I get an answer.

 

Itban Saeed

Hi,

 

May I ask the status of this possible bug ?