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. }