- Home /
Input.location.start always times out
I followed http://docs.unity3d.com/ScriptReference/LocationService.Start.html but on my phone (iOS 8) it times out. I've sent the maxWait and accuracy to 1000. Also, I never got the iOS location permission popup. I had to go into settings and enable it manually. Here's my code, maybe I did something stupid.
IEnumerator GetLocation(){
if (!Input.location.isEnabledByUser){
print("LocationInfo disabled");
yield break;
}
Input.location.Start(1000, 1000);
int maxWait = 1000;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
yield return new WaitForSeconds(1);
maxWait--;
}
if (maxWait < 1) {
print("Timed out");
yield break;
}
if (Input.location.status == LocationServiceStatus.Failed) {
print("Unable to determine device location");
yield break;
}
else if (ParseUser.CurrentUser != null) {
ParseUser user = ParseUser.CurrentUser;
user["Location"] = new ParseGeoPoint(Input.location.lastData.latitude, Input.location.lastData.longitude);
user.SaveAsync();
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
}
Input.location.Stop();
}
After updating to iOS 8.1, I am dealing with the same issue. I used to work correctly, so I assume that it is a new bug from the new version. Did you have any luck dealing with it?
Answer by alvaro-em · Oct 21, 2014 at 03:08 PM
As stated in this thread by pavel_stupka, here it is a workaround for this problem. It was useful for me.
After generating the project with Unity. open it with XCode and:
* Find -> Find in Project
* Search for: startUpdatingLocation
* It should find 2 source files: "iPhone_Sensors.h" and "iPhone_Sensors.mm"
* Open "iPhone_Sensors.h" and add:
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
* Open iPhone_Sensors.mm and before the line:
[locationManager startUpdatingLocation];
Add the following code:
if(IS_OS_8_OR_LATER) {
[locationManager requestAlwaysAuthorization];
}
* At the end add "NSLocationAlwaysUsageDescription" to your Info.plist as a string with your customized message.
Your answer
Follow this Question
Related Questions
Radius around GPS location 1 Answer
LocationService Delegate callback access 0 Answers
Location Service on iOS 1 Answer
Location service initializing forever on iOS devices without GPS. 0 Answers
GPS location string 0 Answers