Question by
TheCGMaster · Sep 20, 2016 at 05:32 PM ·
coordinateslocationgpslocationinfo
GPS coordinates not changing at all!
I am re-creating pokemon go in unity 3D, and I have had trouble with Unity's GPS tracking system. It gets my location, but when i drive/walk it doesnt change! it stays at its starting position. Here is my code :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GPSTracking : MonoBehaviour {
public void Start()
{
StartCoroutine(UpdatePosition());
}
IEnumerator UpdatePosition()
{
if (!Input.location.isEnabledByUser)
GameObject.Find("Failed Text").GetComponent<Text>().text = "You didnt enable device location!!!";
// Start service before querying location
Input.location.Start();
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1)
{
GameObject.Find("Failed Text").GetComponent<Text>().text = "Didnt initilice within 20 seconds!! ";
yield break;
}
// // Connection has failed
if (Input.location.status == LocationServiceStatus.Failed)
{
GameObject.Find("Failed Text").GetComponent<Text>().text = "Unable to determine device location";
yield break;
}
else
{
// Access granted and location value could be retrieved
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
this.transform.position = new Vector3 (Input.location.lastData.latitude, Input.location.lastData.altitude, Input.location.lastData.longitude *) * Time.deltaTime * speed;
GameObject.Find("Cord Text").GetComponent<Text>().text = this.transform.position.x + " : " + this.transform.position.y + " : " + this.transform.position.z;
}
StartCoroutine(UpdatePosition());
// Stop service if there is no need to query location updates continuously
//Input.location.Stop();
}
public float speed;
}
Comment
Your answer
Follow this Question
Related Questions
How can I get 5 decimal places of accuracy for latitude and longitude from locationservice? 3 Answers
Disable updateDistanceInMeters filtering entirely on Input.Location.Start 0 Answers
Location check for mobile app/game 0 Answers
An Exception is occurd when I used Input.location.Start() 0 Answers
Bearing ange from 2 GPS coordinates 1 Answer