Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by eiuolrobles · Apr 12, 2018 at 06:04 PM · unity 5inputif-statementsienumeratorlocation

How to consistently check if GPS is enabled

Hi! I hope someone from the community can help us out. We have an ongoing thesis which is a scavenger hunt-type of game in android and it also needs GPS to be activated. Now I already have a code for the initial error if GPS is not enabled yet once the user launches the app:

 private IEnumerator StartLocationService()
     {
         latitude = Input.location.lastData.latitude;
         longitude = Input.location.lastData.longitude;
 
         if (!Input.location.isEnabledByUser) 
         {
             Debug.Log ("GPS IS DISABLED");
             errorPanel.SetActive (true);
             if (PlayerPrefs.GetInt ("LANG") == 0) 
             {
                 warningMessage.text = "GPS is not enabled. Please activate GPS and try again.";
                 retryButton.text = "Retry";
             }
             if (PlayerPrefs.GetInt ("LANG") == 1) 
             {
                 warningMessage.text = "Hindi nakabukas ang iyong GPS. I-activate and iyong GPS at subukang muli.";
                 retryButton.text = "Ulitin";
             }
             Debug.Log ("GPS is not enabled");
             yield break;
         }
 
         Input.location.Start(10, 0.1f);
         int maxWait = 20;
         while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
         {
             yield return new WaitForSeconds(1);
             maxWait--;
         }
 
         if (maxWait <= 0)
         {
             errorPanel.SetActive (true);
             if (PlayerPrefs.GetInt ("LANG") == 0) 
             {
                 warningMessage.text = "System has timed out. Please try again";
                 retryButton.text = "Retry";
             }
             if (PlayerPrefs.GetInt ("LANG") == 1) 
             {
                 warningMessage.text = "Ang system ay nag-time out. Subukang muli.";
                 retryButton.text = "Ulitin";
             }
             Debug.Log ("Timed out");
             yield break;
         }
 
         if (Input.location.status == LocationServiceStatus.Failed) 
         {
             errorPanel.SetActive (true);
             if (PlayerPrefs.GetInt ("LANG") == 0) 
             {
                 warningMessage.text = "System is unable to determine service location. Please try again";
                 retryButton.text = "Retry";
             }
             if (PlayerPrefs.GetInt ("LANG") == 1) 
             {
                 warningMessage.text = "Hindi matukoy ng system ang iyong lokasyon. Subukang muli.";
                 retryButton.text = "Ulitin";
             }
             Debug.Log ("Unable to determine device location");
             yield break;
         }


Honestly, only the first if condition is the only function that works and im so confused as to how the GPS functions but one of my main concerns is how can I do it so the panel would always show up if ever the user decides to disable it again after enabling the GPS.

Thanks and cheers!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cherrybrandy · May 13, 2018 at 06:45 PM

As far as I know Input.location.isEnabledByUser doesn't check if GPS is enabled, it checks if the user has enabled the location service for this app (or the general phone OS setting, that i don't know). I too am looking for a unity API solution to check wether the user has enabled GPS. Seems we have to use a plugin for this.

Comment
Add comment · 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
0

Answer by ImPHL1 · Jul 14, 2019 at 05:54 PM

hi @eiuolrobles getting latitude and longitude with values of 0 could mean that the GPS is off unless you are exactly in 0,0 (latitude, longitude) location which I don't think that ever gonna happen(really really really low possibility).

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

163 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision Not Working 1 Answer

Is there something wrong with my 'Jump' input axis? 1 Answer

Printing joystick input 0 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Help with if statement 1 Answer


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