IOS developmentDisplay location on Google MapLocationIs the content to be introduced in this article, you can make a line of code to show yourLocation,IOS developmentThe MapKit in integrates the positioning function. You can use a line of code to display your currentLocationThe 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 is used to write 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];
CLLocationManagerDelegate delegate
The 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 longitude = theLocation.coordinate.longitude;
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:IOS developmentDisplay location on Google MapLocationThis article mainly explains how to display your currentLocationFinally, I hope this article will help you!