Android Ultimate Plugin tutorial part 3 – GPS

Today we will show you on how to use GPS on our Android Ultimate Plugin.

Permission needed on your Android Manifest file without this it will not work or it will produce an error.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

let’s start.

First we need to get the instance on the GPSPlugin

private GPSPlugin gpsPlugin = GPSPlugin.GetInstance();

to stop the debugging toast messages from showing pass 0 on SetDebug() method


Next  setup the update interval and minimum meter change for GPS update

long updateInterval = 200; // 200 millsecs

long minimumMeterChangeForUpdate = 0;

0 meter reason it’s a hack because LocationManager in android is a bit buggy and unreliable, this is force GPS to update more frequently

Then initialize our GPS plugin


After that we setup a  listener for OnLocationUpdate , OnEnable, OnGetLocationComplete and OnGetLocationFail Event From GPS

gpsPlugin.SetLocationChangeListener(OnLocationChange,OnEnableGPS,OnGetLocationComplete,OnGetLocationFail );
private void OnLocationChange(double latitude, double longitude){
Debug.Log("[GPSDemo] OnLocationChange latitude: " + latitude + " longitude: " + longitude);

private void OnEnableGPS(string status){
//do something here

private void OnGetLocationComplete(double latitude, double longitude){
        Debug.Log("[GPSDemo] OnGetLocationComplete latitude: " + latitude + " longitude: " + longitude);       

private void OnGetLocationFail(){
   Debug.Log("[GPSDemo] OnGetLocationFail");

To Check if GPS is enable call CheckGPS() Method

bool isEnable = gpsPlugin.CheckGPS();

To ask user to Enable GPS on Their device call ShowGPSAlert() Method


For Getting Latitude call GetLatitude() Method

double latitude = gpsPlugin.GetLatitude();

For Getting Longitude call GetLongitude() Method

double longitude = gpsPlugin.GetLongitude();

To get both Latitude and Longitude call GetLocation() method

string locationSet = gpsPlugin.GetLocation();
string[] locations = locationSet.Split(',');

string latitude =locations.GetValue(0).ToString();
string longitude =locations.GetValue(1).ToString();

or using GetLocationWithCallback method which triggers callback OnGetLocationComplete and OnGetLocationFail


To Stop listening from GPS event call StopGPS() Method


And That’s all , see this is so easy to use!

if you Guys encounter any problem or bugs or error, feel free to email us at or you can comment below

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.