GPS Application with Unity Android

Hi all,
I’ve managed to create a tablet app that uses GPS to set the location of a camera object. I know the tablet is communicating with the unity application because it manages to receive the magnetic compass data and is being displayed as an integer on a GUI interface.
My issue is that i cannot seem to get the GPS module to communicate with the unity android application i have made.
All code i could find online seems to use outdated functions for unity 4.0 and i was wondering if unity android can even access the GPS module?


/* GPS Variables */
var lat : float = 0;		//lattitude , longitude and altitude variables
var lon : float = 0;
var alt : float = 0;
var accuracy : int =10;	//accuracy of the GPS module in m
var distance : int = 10;	// minimum distance before next location variables allocation
var maxWait : int = 20;	//maximum time (s) before time out
var locationStatus : int =0;		

start function

function Start () 
    Input.location.Start();					//enable location settings
	Input.compass.enabled = true;
	locationStatus = LocationServiceStatus.Stopped;

    startLocationService(); 					//begin GPS transmittion

function Update () 
   if(locationStatus == LocationServiceStatus.Running)
		lat = Input.location.lastData.latitude;
		lon = Input.location.lastData.longitude;
		alt = Input.location.lastData.altitude;

GUI.Box(Rect(Screen.width - 200,Screen.height - 50, 100,50), "Latitude => " +lat + "

Longitude => " + lon + "
Altitude => " +alt );


function startLocationService()
    Input.location.Start(accuracy, distance);

    while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) 
	   locationStatus = Input.location.status;

The following code all compiles and runs on the android device but the lat lon and alt values stay as 0

Any suggestions would be great as I’m currently tearing my hair apart at this one!


Hi Ewan,
the problem is that you use locationStatus of type int. And here is the problem
I’ve tried to put Input.location.status instead of it and it is worked well .
and changed after almost ten meters.
also there is yield should be before wait for seconds

I wish that it be benefit to you
and really thank you because it was benefit to me.