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.
– WarrenBShould your script work on its own? If I slapped it on an object in a scene and built it, should it work?
– meat5000I 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 ?
– JonnyHilly