- Home /
The question is answered, right answer was accepted
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?
variables
/* 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;
//print(lat);
//print(lon);
//print(alt);
GUI.Box(Rect(Screen.width - 200,Screen.height - 50, 100,50), "Latitude => " +lat + "\n Longitude => " + lon + "\n Altitude => " +alt );
}
}
function startLocationService()
{
Input.location.Start(accuracy, distance);
while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
WaitForSeconds(1);
maxWait--;
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!
Ewan
Answer by imnimn · Sep 16, 2013 at 07:32 PM
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.
Follow this Question
Related Questions
Unity Android Inputs With Samsung Galaxy Ace 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Android Tablet GPS not working 0 Answers
How do I set my android app to landscape mode entirely? 1 Answer
Facebook unity sdk: is it possible to send friend invites/app requests to non app users ? 1 Answer