GPS address location on Unity iOS platform

Source: Internet
Author: User

You can use the iphonesettings. startlocationserviceupdates () method to start locating service updates. Finally, you can use iphoneinput. lastlocation to retrieve the Location Coordinate variable.

API: static
VoidStartlocationserviceupdates(FloatDesiredaccuracyinmeters=
10f, floatUpdatedistanceinmeters=
10f)

Parameter 1: desiredaccuracyinmeters
-Ideal service accuracy (in meters ). Using a higher value like 500 usually does not need to turn on the GPS chip to keep the battery power, and a value like 5-10 can be used for the best accuracy. The default value is 10 meters.

Parameter 2: updatedistanceinmeters
-A service with the smallest distance (in meters) must be updated before being moved horizontally.Iphoneinput. lastlocationAttribute. For example, 500 means less overhead. The default value is 10 meters.

 

Void start () {// before starting the serviceIphonesettings. startlocationserviceupdates ();// Wait for the Service to be known for initialization
// Iphonesettings. locationservicestatus is the current service status int maxwait = 20; while (iphonesettings. locationservicestatus = locationservicestatus. initializing & maxwait> 0) {yield return waitforseconds (1); maxwait --;} // the service is not initialized within 20 seconds if (maxwait <1) {print ("timed out"); return;} // The user rejects access to the positioning service if (iphonesettings. locationservicestatus = locationservicestatus. failed) {print ("User denied access to device location"); return;} // you can retrieve else {print ("Location:" +Iphoneinput. lastlocation. Latitude+ "" +Iphoneinput. lastlocation. longpolling+ "" +Iphoneinput. lastlocation. Altitude+ "" +Iphoneinput. lastlocation. horizontalaccuracy+ "" +Iphoneinput. lastlocation. Timestamp);} // If you do not need to continuously query and refresh, locate and stop the service iphonesettings. stoplocationserviceupdates ();}

 

Related Article

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.