Languages

Menu
Sites
Language
How can i get gps coordinates

Hi! How can i get coordinates from gps or hybrid location? The sample doesn't work anymore. https://github.com/Samsung/Tizen-CSharp-Samples/tree/master/Wearable/Location In my code, the event isn't triggered.

 

 private async void FetchGpsLocation()
        {
            if (this.locator == null)
            {
                try
                {
                    
                    this.locator = new Locator(LocationType.Hybrid);

                    // Create GpsSatellite instance
                    this.satellite = new GpsSatellite(locator);

                    if (locator != null)
                    {
                        // Starts the Locator which has been created using the specified method.
                        locator.Start();

                        // Add ServiceStateChanged event to receive the event regarding service state
                        locator.ServiceStateChanged += LocatorServiceStateChanged;
                    }
                }
                catch (Exception ex)
                {
                    // Exception handling
                }
            }
        }

        public async void LocatorServiceStateChanged(object sender, ServiceStateChangedEventArgs e)
        {
            if (e.ServiceState == ServiceState.Enabled)
            {
                // Service is enabled

                this.gpsNotFound_.IsVisible = false;
                this.gpsFound_.IsVisible = true;
                double x = this.locator.GetLocation().Longitude;
                double y = this.locator.GetLocation().Altitude;
                List list = await Task.Run(async () => await setTitleGpsAsBusSTop(x, y));
                this.gpsFound_.IsVisible = false;
                this.stopFound_.IsVisible = true;
                this.stop_name_gps_.Text = list[0].stop_name;
                this.stop_dist_gps_.Text = list[0].dist;                
                var list1 = await Task.Run(async () => await setNearestBusStopTimes(list[0].stop_name, list[0].dist, list[0].stop_id));
                clvg.ItemsSource = list1;
                this.loading_Gps.IsRunning = false;
            }
            else
            {
                // Service is disabled
                this.stop_name_gps_.Text = "Gps disattivato";
                this.LoadingGps.IsRunning = false;
            }
        }

 

Edited by: feduss on 22 Oct, 2019
View Selected Answer

Responses

6 Replies
feduss

UP

Tizen .NET

Hi,

Could you let us know how to test it? (e.g. tested on emulator or Galaxy Watch, your watch is paired with phone or not..)

(If possible, please share your execution log with us. you can attach it here or email to us.(tizen.net@samsung.com)

Thanks.

 

 

 

 

feduss

The problem is not my code, but the documentation of how get gps coordinates from galaxy wath's gps....
So, can you please tell me how do this?

I'm talking about this docs --> https://developer.tizen.org/development/guides/.net-application/location-and-sensors/location-information

The problem is that LocatorServiceStateChanged event is never triggered.

Mark as answer
Tizen .NET

Hi,

I know your code is not a problem. In my case, LocatorServiceStateChanged event has been triggered.

(When I test the below code on Galaxy Watch (paired with phone & location option is turned on via settings app), it works.)

void StartLocationService()
        {
            try
            {

                locator = new Locator(LocationType.Hybrid);
                if (locator != null)
                {
                    locator.ServiceStateChanged += Locator_ServiceStateChanged;
                    locator.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occurred: " + ex.GetType() + ", " + ex.Message);
            }
        }

        private void Locator_ServiceStateChanged(object sender, ServiceStateChangedEventArgs e)
        {
            Console.WriteLine("ServiceStateChange " + e.ServiceState.ToString());
            if (e.ServiceState == ServiceState.Enabled)
            {
                Location current = locator.GetLocation();
                Console.WriteLine("Location Info: " + current.Latitude + ", " + current.Longitude + ", " + current.Altitude);
            }
        }

Execution log

10-23 20:12:11.873+0900 I/DOTNET_LAUNCHER(14166): ServiceStateChange Enabled
10-23 20:12:11.893+0900 I/DOTNET_LAUNCHER(14166): Location Info: 37.4660878, 127.02436, 80.1999969482422 

 

feduss
Hi! Idk why, but with this code, the event is triggered...maybe there is a typo error somewhere...thanks :D
Tizen .NET

Anyway, we're double-checking this issue with the person in charge.

I'll share it with you if there's any update.

Thanks.