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();
}
}


}










share|improve this question






















  • 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















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();
}
}


}










share|improve this question






















  • 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













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();
}
}


}










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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();
}
}





share|improve this answer





















  • 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 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




    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













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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();
}
}





share|improve this answer





















  • 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 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




    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

















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();
}
}





share|improve this answer





















  • 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 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




    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















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();
}
}





share|improve this answer












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();
}
}






share|improve this answer












share|improve this answer



share|improve this answer










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 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




    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










  • 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 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




    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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu