How to update gps in unity?
up vote
0
down vote
favorite
I am currently working on ar game through Unity. I am making the game using Vuforia sdk.
GPS coordinates are required within the game, but gps coordinates are not updated.
The strange thing is that in a single application that uses gps code only to display coordinates on the screen, gps coordinates are updated correctly, but if I put the same code into the game, the gps coordinates are no longer updated at the beginning of the application.
I don't think that's a problem with code. Please help.
public class GPSCheck : MonoBehaviour{
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
IEnumerator Start()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
}
c# unity3d gps vuforia
add a comment |
up vote
0
down vote
favorite
I am currently working on ar game through Unity. I am making the game using Vuforia sdk.
GPS coordinates are required within the game, but gps coordinates are not updated.
The strange thing is that in a single application that uses gps code only to display coordinates on the screen, gps coordinates are updated correctly, but if I put the same code into the game, the gps coordinates are no longer updated at the beginning of the application.
I don't think that's a problem with code. Please help.
public class GPSCheck : MonoBehaviour{
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
IEnumerator Start()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
}
c# unity3d gps vuforia
Possible duplicate of How to gps update in unity?
– derHugo
Nov 22 at 17:37
Why did you open a new question asking exactly the same thing again?
– derHugo
Nov 22 at 17:38
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am currently working on ar game through Unity. I am making the game using Vuforia sdk.
GPS coordinates are required within the game, but gps coordinates are not updated.
The strange thing is that in a single application that uses gps code only to display coordinates on the screen, gps coordinates are updated correctly, but if I put the same code into the game, the gps coordinates are no longer updated at the beginning of the application.
I don't think that's a problem with code. Please help.
public class GPSCheck : MonoBehaviour{
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
IEnumerator Start()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
}
c# unity3d gps vuforia
I am currently working on ar game through Unity. I am making the game using Vuforia sdk.
GPS coordinates are required within the game, but gps coordinates are not updated.
The strange thing is that in a single application that uses gps code only to display coordinates on the screen, gps coordinates are updated correctly, but if I put the same code into the game, the gps coordinates are no longer updated at the beginning of the application.
I don't think that's a problem with code. Please help.
public class GPSCheck : MonoBehaviour{
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
IEnumerator Start()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
}
c# unity3d gps vuforia
c# unity3d gps vuforia
asked Nov 22 at 14:02
Jayum
1
1
Possible duplicate of How to gps update in unity?
– derHugo
Nov 22 at 17:37
Why did you open a new question asking exactly the same thing again?
– derHugo
Nov 22 at 17:38
add a comment |
Possible duplicate of How to gps update in unity?
– derHugo
Nov 22 at 17:37
Why did you open a new question asking exactly the same thing again?
– derHugo
Nov 22 at 17:38
Possible duplicate of How to gps update in unity?
– derHugo
Nov 22 at 17:37
Possible duplicate of How to gps update in unity?
– derHugo
Nov 22 at 17:37
Why did you open a new question asking exactly the same thing again?
– derHugo
Nov 22 at 17:38
Why did you open a new question asking exactly the same thing again?
– derHugo
Nov 22 at 17:38
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
First : you don't start your coroutine.
Second : Avoid using Unity methode as coroutine.
Try this :
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
private void Start()
{
StartCoroutine(GSP());
}
private IEnumarator GSP()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
2
@Samuel Thauvin Apouchkal what is the reason to not useStart
as anIEnumerator
in this case if anyway the only thing it does is starting the coroutine? IfStart
is defined asIEnumerator
Unity automatically starts it as Coroutine instead of a method call.
– derHugo
Nov 22 at 17:33
2
It's even what they use as example
– derHugo
Nov 22 at 17:40
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
|
show 3 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
First : you don't start your coroutine.
Second : Avoid using Unity methode as coroutine.
Try this :
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
private void Start()
{
StartCoroutine(GSP());
}
private IEnumarator GSP()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
2
@Samuel Thauvin Apouchkal what is the reason to not useStart
as anIEnumerator
in this case if anyway the only thing it does is starting the coroutine? IfStart
is defined asIEnumerator
Unity automatically starts it as Coroutine instead of a method call.
– derHugo
Nov 22 at 17:33
2
It's even what they use as example
– derHugo
Nov 22 at 17:40
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
|
show 3 more comments
up vote
0
down vote
First : you don't start your coroutine.
Second : Avoid using Unity methode as coroutine.
Try this :
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
private void Start()
{
StartCoroutine(GSP());
}
private IEnumarator GSP()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
2
@Samuel Thauvin Apouchkal what is the reason to not useStart
as anIEnumerator
in this case if anyway the only thing it does is starting the coroutine? IfStart
is defined asIEnumerator
Unity automatically starts it as Coroutine instead of a method call.
– derHugo
Nov 22 at 17:33
2
It's even what they use as example
– derHugo
Nov 22 at 17:40
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
|
show 3 more comments
up vote
0
down vote
up vote
0
down vote
First : you don't start your coroutine.
Second : Avoid using Unity methode as coroutine.
Try this :
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
private void Start()
{
StartCoroutine(GSP());
}
private IEnumarator GSP()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
First : you don't start your coroutine.
Second : Avoid using Unity methode as coroutine.
Try this :
public static double first_Lat;
public static double first_Long;
public static double current_Lat;
public static double current_Long;
private static WaitForSeconds second;
private static bool gpsStarted = false;
private static LocationInfo location;
private void Awake()
{
second = new WaitForSeconds(1.0f);
}
private void Start()
{
StartCoroutine(GSP());
}
private IEnumarator GSP()
{
if (!Input.location.isEnabledByUser)
{
Debug.Log("GPS is not enabled");
yield break;
}
Input.location.Start(5f, 10f);
Debug.Log("Awaiting initialization");
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return second;
maxWait -= 1;
}
if (maxWait < 1)
{
Debug.Log("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed)
{
Debug.Log("Unable to determine device location");
yield break;
}
else
{
location = Input.location.lastData;
first_Lat = location.latitude * 1.0d;
first_Long = location.longitude * 1.0d;
gpsStarted = true;
while (gpsStarted)
{
location = Input.location.lastData;
current_Lat = location.latitude * 1.0d;
current_Long = location.longitude * 1.0d;
yield return second;
}
}
}
public static void StopGPS()
{
if (Input.location.isEnabledByUser)
{
gpsStarted = false;
Input.location.Stop();
}
}
answered Nov 22 at 14:12
Samuel Thauvin Apouchkal
13
13
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
2
@Samuel Thauvin Apouchkal what is the reason to not useStart
as anIEnumerator
in this case if anyway the only thing it does is starting the coroutine? IfStart
is defined asIEnumerator
Unity automatically starts it as Coroutine instead of a method call.
– derHugo
Nov 22 at 17:33
2
It's even what they use as example
– derHugo
Nov 22 at 17:40
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
|
show 3 more comments
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
2
@Samuel Thauvin Apouchkal what is the reason to not useStart
as anIEnumerator
in this case if anyway the only thing it does is starting the coroutine? IfStart
is defined asIEnumerator
Unity automatically starts it as Coroutine instead of a method call.
– derHugo
Nov 22 at 17:33
2
It's even what they use as example
– derHugo
Nov 22 at 17:40
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
This code also does not update gps coordinates in my game..T.T
– Jayum
Nov 22 at 14:31
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
In a gps test application, can a code that works well not go back to the game? Even if the code is completely identical?
– Jayum
Nov 22 at 14:33
2
2
@Samuel Thauvin Apouchkal what is the reason to not use
Start
as an IEnumerator
in this case if anyway the only thing it does is starting the coroutine? If Start
is defined as IEnumerator
Unity automatically starts it as Coroutine instead of a method call.– derHugo
Nov 22 at 17:33
@Samuel Thauvin Apouchkal what is the reason to not use
Start
as an IEnumerator
in this case if anyway the only thing it does is starting the coroutine? If Start
is defined as IEnumerator
Unity automatically starts it as Coroutine instead of a method call.– derHugo
Nov 22 at 17:33
2
2
It's even what they use as example
– derHugo
Nov 22 at 17:40
It's even what they use as example
– derHugo
Nov 22 at 17:40
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
it's an IEnumerator Start() not an void Start()
– Samuel Thauvin Apouchkal
Nov 23 at 15:46
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432674%2fhow-to-update-gps-in-unity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of How to gps update in unity?
– derHugo
Nov 22 at 17:37
Why did you open a new question asking exactly the same thing again?
– derHugo
Nov 22 at 17:38