Code control open permissions and get latitude and longitude:
public string gps_info = "";
public int flash_num = 1;
public float N;
public float e;
Public IEnumerator Startgps ()
{
Input.location used to access the device's location properties (handheld device), static locationservice position
Locationservice.isenabledbyuser whether the location service is enabled in the user settings
if (! Input.location.isEnabledByUser)
{
This.gps_info = "Isenabledbyuser value is:" + Input.location.isEnabledByUser.ToString () + "Turn on the GPS";
}
Locationservice.start () Start update of location service, the last location coordinates will be used
Input.location.Start (10.0f, 10.0f);
int maxwait = 20;
while (Input.location.status = = locationservicestatus.initializing && maxwait > 0)
{
Pausing the execution of a synergistic program (1 seconds)
Yield return new waitforseconds (1);
maxwait--;
}
if (Maxwait < 1)
{
This.gps_info = "Init GPS service Time Out";
}
if (Input.location.status = = locationservicestatus.failed)
{
This.gps_info = "Unable to determine device location";
}
Else
{
This.gps_info = "N:" + Input.location.lastData.latitude + "E:" + Input.location.lastData.longitude;
This.gps_info = This.gps_info + "Time:" + Input.location.lastData.timestamp;
n = Input.location.lastData.latitude;
e = Input.location.lastData.longitude;
Yield return new waitforseconds (100);
}
}
Get GPS information for mobile devices in unity