One rowCodeShow your location
Mapkit in IOS integrates the positioning function. You can use a line of code to display your current location on Google map. The Code is as follows:
-(Ibaction) showlocation :( ID) sender {If ([btnshowlocation titleforstate: uicontrolstatenormal] isequaltostring: @ "show my location"]) {[btnshowlocation settitle: @ "hide my location" forstate: uicontrolstatenormal]; mapview. showsuserlocation = yes;} else {[btnshowlocation settitle: @ "show my location" forstate: uicontrolstatenormal]; mapview. showsuserlocation = no ;}}
The key code is mapview. showuserlocation = yes.
Use cllocationmanager and mkmapview In addition, the corelocation framework writes code to request the current location, which is also very simple: Step 1: Create a cllocationmanager instance
Cllocationmanager * locationmanager = [[cllocationmanager alloc] init];
Step 2: Set the cllocationmanager instance delegation and precision
Locationmanager. Delegate = self; locationmanager. desiredaccuracy = kcllocationaccuracybest;
Step 3: Set the distance filter distancefilter. The following indicates that the device must be at least 1000 meters moved before the delegated update is notified.
Locationmanager. distancefilter = 1000.0f;
Or the default settings without filters are as follows:
Locationmanager. distancefilter = kcldistancefilternone;
Step 4: Start the request
[Locationmanager startupdatinglocation];
Use the following code to stop a request:
[Locationmanager stopupdatinglocation];
The cllocationmanagerdelegate delegate includes the locationmanager: didupdatetolocation: fromlocation method to obtain the longitude and latitude. You can use the following code to obtain the longitude and latitude from the cllocation instance:
Cllocationdegrees latitude = thelocation. Coordinate. Latitude; cllocationdegrees longpolling = thelocation. Coordinate. longpolling;
Use the following code to obtain your altitude:
Cllocationdistance altitude = thelocation. altitude;
Use the following code to obtain your displacement: Cllocationdistance distance = [Fromlocation distancefromlocation: tolocation];
Summary:This article mainly explains how to display your current location on the iOS device Google map.