hi. is there something about Input.location that I don’t know?
because it gives me the right latitude and longitude only when I turn on location of my phone before running the game(exactly before)!! and lets say I start the game with location on, if I turn off location and turn it on again I will get latitude and longitude zero forever unless I close the game and start it again!!
thnaks
@Hellium
public void GetUserLocation(){
//FIRST IM CHACKING FOR PERMISSION IF "true" IT MEANS USER GAVED PERMISSION FOR USING LOCATION INFORMATION
if(!Input.location.isEnabledByUser){
statusTxt.text = "No Permission__ ";
}
else
{
statusTxt.text = "Ok Permission__ ";
StartCoroutine("GetLatLonUsingGPS");
}
}
IEnumerator GetLatLonUsingGPS()
{
// Start service before querying location
Input.location.Start();
// Service didn't initialize in 10 seconds
int maxWait = 10;
while( Input.location.status == LocationServiceStatus.Initializing && maxWait > 0 )
{
yield return new WaitForSeconds(1);
maxWait--;
}
if( maxWait < 1 )
{
statusTxt.text = "Failed To Iniyilize in 10 seconds";
yield break;
}
// Connection has failed
if( Input.location.status == LocationServiceStatus.Failed )
{
Debug.Log("Unable to determine device location");
statusTxt.text = "Failed To Iniyilize";
yield break;
}
else
{
// Access granted and location value could be retrieve
string longitude = Input.location.lastData.longitude.ToString();
string latitude = Input.location.lastData.latitude.ToString();
AddLocation(double.Parse(latitude), double.Parse(longitude));
Debug.Log("lat:"+latitude+" long:"+longitude);
statusTxt.text="" + Input.location.status + " lat:"+latitude+" long:"+longitude;
if(latitude!="0"){
Input.location.Stop();
StopCoroutine("Start");
statusTxt.text = "" + Input.location.status + " lat it is:" + latitude ;
}
}
//Stop retrieving location
Input.location.Stop();
}
//
}