- Home /
How do I make LocationService.Start work?
HI, I been looking in the forums post like "How to get GPS coordinates in unity 3d" and they all link to the documentation "http://docs.unity3d.com/ScriptReference/LocationService.Start.html", but I can't make it work :c
The example screen is:
function Start () {
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser)
return;
// Start service before querying location
Input.location.Start ();
// Wait until service initializes
var maxWait : int = 20;
while (Input.location.status
== LocationServiceStatus.Initializing && maxWait > 0) {
yield WaitForSeconds (1);
maxWait--;
}
// Service didn't initialize in 20 seconds
if (maxWait < 1) {
print ("Timed out");
return;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed) {
print ("Unable to determine device location");
return;
}
// Access granted and location value could be retrieved
else {
print ("Location: " + Input.location.lastData.latitude + " " +
Input.location.lastData.longitude + " " +
Input.location.lastData.altitude + " " +
Input.location.lastData.horizontalAccuracy + " " +
Input.location.lastData.timestamp);
}
// Stop service if there is no need to query location updates continuously
Input.location.Stop ();
}
The error If some body know how to get get GPS coordinates, it would be really appreciated Thanks in advance : )
Answer by meat5000 · Nov 30, 2015 at 03:48 PM
You need to put some info in to the start method.
Input.location.Start (1,0.1);
Use these to check if its enabled by the user in Hardware and its status.
Also, I think you are mixing C# and JS in your script.
Use:
#pragma strict
import UnityEngine;
import System.Collections;
public class GPS extends MonoBehaviour
{
Thanks four taking the time to help me
I fix what a thing was the problem ( i was working on C# and apparently ir was a Java script ) Now In not sure if its working, but at least is working more than before XD The scene is playable, but the GPS coordinates are nowhere to be found
You may need to output them to a GUI, like OnGUI.
You can output them to the console just to see if its working.
Note that the examples in the Docs can be changed between C# and JS by clicking near the upper right corner.
The code I added my my answer is for the JS version
Answer by DVFrance · Aug 17, 2016 at 02:18 PM
Hi, is there any solution to test GPS coordinate without building. I think it's a lost of time needing building to know if the code works or not ? I'm working on a mac with location services enable and unity editor console still saying Input.location.isEnabledByUser is false...
Your answer
![](https://koobas.hobune.stream/wayback/20220612050740im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GPS coordinates (lat/long/altitude) to Unity 3D coordinates (x, y, z) 1 Answer
how to convert gps coordinates to unity 2 Answers
GPS doesn't work in AGPS mode 0 Answers
Are there examples of GPS-based indoor item placement apps? 0 Answers
How can i get gps signal on my andriod without data or wifi 0 Answers