• banner contest_big deadline

    Deadline
    Extended!!

    To give more time to developers 
    we have decided to extend
    Cell·APP Awards until June 15th.

  •     Developed with CELL·SDK

    img zombeee

    google iOS WP

  • banner contest_big 

                    Vote Now!

    You can vote and be voted until 
    June 22nd! Vote and Share 
    the best application on
    facebook, twitter... 

    podium
  • slide pitada

     Pitada contra 
    el Hambre

    Multiplatform Application 
    developed by TheGameKitchen 
    using CELL·SDK.

  • Easy of Use
    and Great Potential

    High level API linked to that
    which creates applications,
    obtaining maximun profitability
    thanks to automatic translation
    and native code.

    img gallery
  • Official Emulator

    CELL·SDK allows you to debug your
    applications using the official
    emulators of Android, iOS and
    Windows Phone, increasing the
    reliability of your rest.

    img gallery 05

  home text  

Uses C# to create applications on Android, iOS
and Windows Phone.  

 

    devices home  

bt new_trial_downloadbt quick_tour 

GPS

Welcome to another Cell•SDK tutorial.

Once upon a time Willy Fog went around the word in eighty days, but if he had got Cell•SDK, well, that would be another story. So let Mr. Fog to teach us in the use of GPS in Cell•SDK.

Mr. Fog:

Hello dears! The world I have always been a wordless man, so just create a new Cell•SDK project to see the GPS functionality in action.

We are going to access the device’s GPS to get the latitude and longitude to show it in the screen, so add two labels as private class variables to be able to represent the data in some Update’s method execution. I have said “some” because we shouldn’t do it in every execution, we will refresh the data every second, so we will need a timer too. So add these class variables:

 

private Label lblLatitude, lblLongitude;
private TimeSpan timer;

 

Now create, and add the Labels to the screen with this lines in the Initialize method:

 

lblLatitude = new Label("Latitude: ");
lblLongitude = new Label("Longitude: ");
 
AddComponent(lblLatitude, Preferences.Width / 4, Preferences.Height / 8);
AddComponent(lblLongitude, Preferences.Width / 4, Preferences.Height / 4);

 

We have used Preferences.Width/X structure due to different device screens resolutions.

Ok, now remember, as you saw in other tutorials, that accessed the device hardware we will need to initialize the device and stop it at the application exit at least.

We need to add a reference to the LocationSystem dll which allow us to use the GPS that can be located under Cell•SDK/Versions/ and add a using statement like:

 

using Syderis.CellSDK.IO.LocationSystem;

 

To initialize the GPS and start to be able to read data we call, but do not forgot to check if GPS is connected. Add this class variable:

 

private bool isConnected;

 

Check if GPS is connected:

 

if (isConnected)
    LocationSensor.Instance.Start(LocationSensors.GPS);
else
    Preferences.App.Alert("GPS sensor is not available on this device", "Warning!");

 

With that line, the GPS start to read the information needed to be capture.

So it is time to represent it. We will override Update() method to set the label text only every second using the timer we created before:

 

public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
{
    base.Update(gameTime);
    
    if (!isConnected)
        return;
    timer += gameTime.ElapsedGameTime;
    if (timer > TimeSpan.FromSeconds(1))
    {
        lblLatitude.Text = string.Format("Latitude: {0}", Syderis.CellSDK.IO.LocationSystem.LocationSensor.Instance.GeoLocation.latitude);
        lblLongitude.Text = string.Format("Longitude: {0}", Syderis.CellSDK.IO.LocationSystem.LocationSensor.Instance.GeoLocation.longitude);
        timer = TimeSpan.Zero;
    }
}

 

If we run we will get this:

gps1

Once again, do not foget to stop GPS when you exit the application:

 

public override void BackButtonPressed()
{
    base.BackButtonPressed();
    
    if(isConnected)
        LocationSensor.Instance.Stop(LocationSensors.GPS);
}

 

We can acces more information like altitude, course and speed. So it is your turn in making great applications that uses them.

"Keep on cool coding."

You can get the code in Github

Social Network

This e-mail address is being protected from spambots. You need JavaScript enabled to view it.