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 /
  • Help Room /
avatar image
0
Question by Deeaammon · Feb 22, 2017 at 11:14 PM · androidgpslocationinfo

Unity5 and Unity Remote 5 will not work with GPS on my Android lolipop 6.01 phone

So I have a Android Lollipop 6.0.1. I have gone through the tutorials to make it work with accelerometer, gyro and compass. All of which work. However it always seems to think that the GPS on my phone is not enabled even though it is.

This is the same after I compile it it and install it on the phone and if a try to run it through Unity Remote 5.

Am I missing an extra setting? My GPS Location is turned on on my phone and it works with other phone apps. Just not the Unity ones that I'm trying to create. I'm just trying to get simple latitude and longitude data

The code I am using is below. I only get to the point in the code !Input.location.isEnabledByUser and it kicks me out with the Debug.Log "user has not enabled gps"

Thanks All, hope you can help.

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class GPS : MonoBehaviour {
     public static GPS Instance { set; get; }
     public float latitude;
     public float longitude;
 
     private void Start()
     {
         
         Instance = this;
         DontDestroyOnLoad(gameObject);
         StartCoroutine(StartLocationService());
 
     }
 
     private IEnumerator StartLocationService()
     {
         
         if (!Input.location.isEnabledByUser)
         {
             Debug.Log("user has not enabled gps");
             yield break;
         }
 
         Input.location.Start();
         int maxWait = 20;
         while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
         {
             yield return new WaitForSeconds(1);
             maxWait--;
         }
 
         if (maxWait <= 0)
         {
             Debug.Log("Timed Out");
             yield break;
         }
 
         if(Input.location.status == LocationServiceStatus.Failed)
         {
             Debug.Log("Unable to dtermine device location");
             yield break;
         }
 
 
         latitude = Input.location.lastData.latitude;
         longitude = Input.location.lastData.longitude;
         yield break;
     }
 }
 

Comment
Add comment · Show 1
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 AugmentedExistence · Mar 13, 2017 at 06:03 PM 0
Share

Same problem. Ever get it going?

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by juldaani · Mar 23, 2017 at 01:48 PM

I had exactly the same problem. The solution which worked for me was to add some delay into StartLocationService(). I think the problem is that Unity Remote and Unity Editor require some time to establish a connection. If you try to start the location service before the connection between remote and editor is established you will fail. This will happen if you try to start location service in the start().

See my solution below:

 private IEnumerator StartLocationService(float desiredAccuracyInMeters, float updateDistanceInMeters)
     {
         // Wait until the editor and unity remote are connected before starting a location service
         if (isUnityRemote)
         {
             yield return new WaitForSeconds(5);
         }
 
         // First, check if user has location service enabled
         if (!Input.location.isEnabledByUser)
         {
             Debug.Log("No locations enabled in the device");
             yield break;
         }
 
         // Start service before querying location
         Input.location.Start();
 
         if (isUnityRemote)
         {
             yield return new WaitForSeconds(5);
         }
 
         // Wait until service initializes
         int maxWait = 20;
         while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
         {
             yield return new WaitForSeconds(1);
             maxWait--;
         }
 
         // Service didn't initialize in 20 seconds
         if (maxWait < 1)
         {
             Debug.Log("Service didn't initialize in 20 seconds");
             yield break;
         }
 
         // Connection has failed
         if (Input.location.status == LocationServiceStatus.Failed)
         {
             Debug.Log("Unable to determine device location");
             yield break;
         }
         // Access granted and location value could be retrieved
         else
         {
             float lat = Input.location.lastData.latitude;
             float lon = Input.location.lastData.longitude;

         }
     }

I added 2 seconds delay in the beginning of the StartLocationService() and directly after the Input.location.Start(). I also made a global boolean isUnityRemote to be able to disable these delays if I want. You could also use "Input.location.status == LocationServiceStatus.Running" in the while loop instead of this if you want to be more elegant.

Comment
Add comment · Show 2 · 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 TrickiDicki · Jul 09, 2017 at 09:15 AM 0
Share

Thanks for the tip - adding a delay on start-up seems to have fixed it for me!

avatar image Galaxy_Surfer · Oct 19, 2018 at 11:46 PM 0
Share

Thank you very much! The delays also fixed my issues with the Remote 5 app using GPS data.

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

152 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

Related Questions

How can I get 5 decimal places of accuracy for latitude and longitude from locationservice? 3 Answers

GPS power consumption 0 Answers

how to place 2d/3d objects in real world based on location and altitude... 0 Answers

Trying to Build GPS Tracking Based App, Help 0 Answers

Augmented Reality Navigation 0 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