• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tjoppie152 · Jul 30, 2014 at 10:07 AM · gps

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. }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WarrenB · Aug 05, 2014 at 04:06 PM 0
Share

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.

avatar image meat5000 ♦ · Aug 05, 2014 at 08:14 PM 0
Share

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

avatar image JonnyHilly · Feb 10, 2015 at 10:10 AM 0
Share

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 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by meat5000 · Aug 05, 2014 at 04:09 PM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WarrenB · Aug 05, 2014 at 04:18 PM 0
Share

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 $$anonymous$$utes.

I wonder if it is using WIFI positioning (superseding GPS) and assu$$anonymous$$g 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.

avatar image meat5000 ♦ · Aug 05, 2014 at 06:27 PM 0
Share

It seems you can not specify where the information comes from. That is down to what Android chooses to feed given the options defined. It will attempt to reconcile all allowed location inputs into one location 'answer'.

Check your location services on device and see what is going on.

Aside from this, it seems Unity's API is limited in this department. $$anonymous$$aybe you can access the Android location service more directly, but I can't see a way to force an update with Unity.

Try Device Only (GPS $$anonymous$$ODE) and then try Battery Saving (WIFI/$$anonymous$$OBILE) to see if there is any difference.

Also try High Accuracy mode with and without Wifi switched on.

avatar image Tjoppie152 · Aug 07, 2014 at 05:28 PM 0
Share

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 assu$$anonymous$$g 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?

avatar image meat5000 ♦ · Aug 07, 2014 at 10:39 PM 0
Share

Have you Accepted the Google Wifi Data Agreement that flashes up when you enable location?

Check out Andreas answer on this page. It suggests to confirm what I mentioned above in the final line of my answer.

The thing is, under GPS even when accuracy is set to 1 metre and the device is held very still, you can still see the figures updating, even if it is just the last digit. This implies that there are updates regardless of whether the device has moved or not.

It could be Google's attempt at making people hand over their information. Selecting Decline could seem to sabotage the system so as to make people select yes.

I'm afraid I'm not going to test this theory. I'm not going to consent.

avatar image
0

Answer by tanoshimi · Aug 05, 2014 at 06:30 PM

You can always write a plugin to access the device GPS readings directly: http://www.mat-d.com/site/unity-gps-plugin-development-tutorial-building-a-android-plugin-for-unity-with-eclipse-and-ant/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tjoppie152 · Aug 07, 2014 at 05:00 PM 0
Share

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?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Android Inputs With Samsung Galaxy Ace 0 Answers

Why I can't get GPS information on Android device 0 Answers

Cant get the gps on my android when i am not connected to the wifi 0 Answers

GPS check current location with longitude and latitude of multiple locations in XML 0 Answers

Can't get GPS data on Windows Phone 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges