Unity uses GPS API s
In unity's official documents, there are only two API s related to device positioning (GPS longitude and latitude, horizontal accuracy, etc.) that I have found at present: Location Service and Location Info.
Let's start with a simple understanding:
Location Service is responsible for starting and closing location services.
Location Info obtains location data information after the service starts.
LocationService
Links to official notes:
http://docs.Unity3D.com/Documentation/ScriptReference/LocationService.Start.html
Location Service has three attributes and two methods:
(1) isEnabled ByUser -- Whether the location service in the user settings is enabled. (The measured results show that all of them are true, which seems to have little effect.)
(2) lastData -- Location Info lastData; that is, it's associated with Location Info
(3) Status -- Locate the status of the service.
The status of location services includes:
Stopped
Location service is stopped. Location service has stopped
Initializing
Location service is initializing, some time later it will switch to. Location service is initializing, after a period of time, the state will switch back.
Running
Location service is running and locations can be queried. Location service is running and location can be obtained.
Failed
Location service failed (user denied access to location service). Location service failed (user denied access to location service).
(4) Start () -- Start location service and update location data. Recent updated position coordinates can be obtained.
Data reception is achieved through Input.location.lastData. The service cannot get location data immediately. The code must check Input.location.status to get the current location service status.
Look at the function definition:
void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f);
Detailed parameters:
The precision required for desired Accuracy InMeters service is in meters. If you use a higher value, such as 500, you don't usually need to turn on the GPS chip (such as triangulation using the signal base station) to save battery power. Values like 5-10 can be used to achieve optimal accuracy. The default value is 10 meters.
(5) Stop () -- Stop location updates for location services. This is very useful for saving battery power. void
LocationInfo
The attributes are as follows:
(1) altitude - altitude
(2) horizontal Accuracy -- horizontal accuracy
(3) latitude - latitude
(4) longitude -- longitude
(5) timestamp -- the timestamp of the last location, starting in 1970
(6) Vertical Accuracy -- Vertical Accuracy
All of these attributes are float except that timestamp is double.
Here's an example of Unity using GPS
1. Create a new project.
2. Write the script GetGPS.cs and hang it on the main camera.
3. Export to the mobile phone, run, you can see the effect.