- Home /
input.location not updating on Iphone
I'm building a simple location based game using GPS. I used some example code, but it seems the GPS is not updating after the finding the initial position. It only updates if i swap apps or something. For our game I need it to update every few seconds. I tried putting the "input.location" in the Update class, but got the same results. I'm using an Iphone 4 with IOS 5.1 and unity 3.5.5
Here is roughly the code i'm using:
using UnityEngine;
using System.Collections;
public class question : MonoBehaviour {
public float mylat;
public float mylong;
public float posScale = 1;
public Vector2 globalPos;
bool gpsRunning = false;
public float gpsAccuracy = 100;
public float gpsUpdateDistance = 10;
private bool ready = false;
public TextMesh coordText;
Vector2 MDMloc = new Vector2(49.267356f,-123.090309f);
// Use this for initialization
void Start () {
globalPos = new Vector2(MDMloc.y,MDMloc.x);
StartGPS();
}
// Update is called once per frame
void Update () {
// globalPos.x = Input.location.lastData.latitude;
// globalPos.y = Input.location.lastData.longitude;
mylat = (globalPos.x % 1) * 1000;
mylong = (globalPos.y % 1) * 1000;
transform.position = new Vector3(mylat*posScale, mylong*posScale, transform.position.z);
coordText.text = "iphone gps: (" + globalPos.x + "," + globalPos.y + ")";
coordText.renderer.material.color = new Color(1,0,0);
}
IEnumerator ActivateGPS() {
gpsRunning = true;
Input.location.Start(gpsAccuracy, gpsUpdateDistance);
if (Input.location.status == LocationServiceStatus.Running)
Debug.Log("**** LocationService Running");
float duration = 0;
while (duration < 20.0f) {
if (Input.location.status == LocationServiceStatus.Running
|| Input.location.status == LocationServiceStatus.Failed) break;
yield return new WaitForSeconds(0.1f);
duration += 0.1f;
}
if (duration >= 20.0f) {
Debug.Log("**** LocationService Timed out");
}
if (Input.location.status == LocationServiceStatus.Failed) {
Debug.Log("**** User declined LocationService?");
gpsRunning = false;
}
while (Input.location.status == LocationServiceStatus.Running) {
globalPos.y = Input.location.lastData.latitude;
globalPos.x = Input.location.lastData.longitude;
yield return new WaitForSeconds(2.0f);
}
}
public void StartGPS() {
if (Application.isEditor) {
return;
}
if (!gpsRunning) StartCoroutine(ActivateGPS());
}
public void StopGPS() {
Input.location.Stop();
gpsRunning = false;
}
void OnApplicationQuit() {
StopAllCoroutines();
Input.location.Stop();
}
}
I am having the exact same problem. The postion only update very infrequent even if I move more than 100m?
Did you find a solution to this?
Regards Jens
Your answer
Follow this Question
Related Questions
Proximity iPhones alert 2 Answers
GPS on iPhone 6 giving me fits, will not Initialize and never asks me to enable 1 Answer
Input.location.start always times out 1 Answer
GPS location string 0 Answers