Unity3d location services not updating regularly

Hello to you all,

Im a bit a noob programmer so i hope someone can help me with this. I am trying to create a script so that I can get my walking speed with an android device using the GPS but Input.location.lastData does not update as regularly as it does with other GPS apps on my samsung so im thinking it has got to be my script. When walking it won’t update my location even after 5 minutes of walking outside with clear skies, when driving it would update the location a few times. Has anybody had this kind of issue? Below is my code.

 1. #pragma strict 
 2. 
 3. var tim;
 4. var Lat;
 5. var Lon;
 6. 
 7. function Start () {
 8.         // First, check if user has location service enabled
 9.         if (!Input.location.isEnabledByUser)
 10.             return;
 11.         // Start service before querying location
 12.         Input.location.Start (5,5);
 13.         // Wait until service initializes
 14.         var maxWait : int = 20;
 15.         while (Input.location.status
 16.                == LocationServiceStatus.Initializing && maxWait > 0) {
 17.             yield WaitForSeconds (1);
 18.             maxWait--;
 19.         }
 20.         // Service didn't initialize in 20 seconds
 21.         if (maxWait < 1) {
 22.             print ("Timed out");
 23.             return;
 24.         }
 25.         // Connection has failed
 26.         if (Input.location.status == LocationServiceStatus.Failed) {
 27.             print ("Unable to determine device location");
 28.             return;
 29.         }
 30.        // Access granted and location value could be retrieved
 31. 
 32.  function Update ()
 33. {
 34.   Lat = Input.location.lastData.latitude;  
 35.   Lon = Input.location.lastData.longitude;
 36. }
 37. 
 38. function OnGUI()
 39. {
 40.   GUI.Label (Rect (10, 70, 1000, 1000), "Lat : " +Lat);
 41.   GUI.Label (Rect (10, 100, 100, 20), "Lon : " +Lon);   
 42. }

I am having the same problem! This is in a professional environment where it has been verified in different areas of the country, under different conditions on different phones. GPS does not update often enough. I can't upvote yet, but this is a big problem for me too! Someone please help.

–

Should your script work on its own? If I slapped it on an object in a scene and built it, should it work?

–

I have the same problem, (on iOS 8, but works fine on iOS7 !!!) its always stuck in initializing state. Even if user turns on location Services manually to 'always' in device settings, OS8 turns it off again after running the app. I have location-services device requirement on in Xcode (tried both on and off) I cannot turn on GPS requirement, as this would exclude all WiFi only devices. Is this a UNity3D bug ?

–

2 Answers

2

Default value is 10 meters.
updateDistanceInMeters - the minimum
distance (measured in meters) a device
must move laterally before
Input.location property is updated.

http://docs.unity3d.com/ScriptReference/LocationService.Start.html


EDIT: I tried your script above. I set
the desired accuracy to 1 metre, I set
the update distance to 0.1 metres. I
went outside for a wander… As soon
as my device picked up the satellite
my location updated slightly under
Once per Second. Device : Xperia Z - GPS-only mode

Using Wifi and Network, the device
would begin updating once a second,
then stop for a while, and at some
undefined time would begin updating
again at 1/s.

Switching DEVICE WIFI OFF (So just Network), the figures updated just fine, switching WIFI back on made it stop.

The problem is WIFI LOCATION not functioning correctly. Your router doesn’t know where it is and its interfering with the network location, in this mode.

Looking at this page suggests that selecting DECLINE to Googles wifi location data collection may render WIFI positioning unusable.

If I understand correctly, something like this: Input.location.Start(1,1); says give me very fine measurements (approximately 1 meter accuracy) and alert me whenever the position changes by more than 1 meter. This code still my not update over 30 meters distance and 2 minutes. I wonder if it is using WIFI positioning (superseding GPS) and assuming the position hasn't changed as long as I has signal from the same access point. So it doesn't query for GPS changes until you move far enough to view different networks and trigger a refresh? I'm grasping at straws here.

–

Hi meat 5000, tried your suggestions and it is working perfectly if you run on GPS only mode and set the Input.location.Start(0.1,0.1); . So I think your right about Unity assuming the position has'nt changed because of network location. Do you think there is a way to fix this issue without having to switch of all wifi and network access before running the app?

–

You can always write a plugin to access the device GPS readings directly: Unity GPS plugin development tutorial: building a Android plugin for Unity with Eclipse and Ant | Matthieu Deru - Mat-D.com

Hey guys, thanks a lot for all the answers. I tried creating the plugin from mat-d's site but can't get it working on unity. Think it might be because of the version difference since he made the tutorial. Were you able to get it working with unity 4.5?

–