Get GPS information for mobile devices in unity

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.