IOS development: Display location on Google Map

Source: Internet
Author: User

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:

 
 
  1. -(IBAction) showLocation:(id) sender {    
  2.     if ([[btnShowLocation titleForState:UIControlStateNormal]     
  3.          isEqualToString:@"Show My Location"]) {    
  4.         [btnShowLocation setTitle:@"Hide My Location"    
  5.                         forState:UIControlStateNormal];    
  6.         mapView.showsUserLocation = YES;            
  7.     } else {    
  8.         [btnShowLocation setTitle:@"Show My Location"    
  9.                         forState:UIControlStateNormal];    
  10.         mapView.showsUserLocation = NO;    
  11.     }        
  12. }  

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

 
 
  1. CLLocationManager *locationManager = [[CLLocationManager alloc] init];  

Step 2: Set the CLLocationManager instance delegation and precision

 
 
  1. locationManager.delegate = self;     
  2. 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.

 
 
  1. locationManager.distanceFilter = 1000.0f;  

Or the default settings without filters are as follows:

 
 
  1. locationManager.distanceFilter = kCLDistanceFilterNone;  

Step 4: Start the request

 
 
  1. [locationManager startUpdatingLocation];  

Use the following code to stop a request:

 
 
  1. [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:

 
 
  1. CLLocationDegrees latitude = theLocation.coordinate.latitude;     
  2. CLLocationDegrees longitude = theLocation.coordinate.longitude;  

Use the following code to obtain your altitude:

 
 
  1. CLLocationDistance altitude = theLocation.altitude;  

Use the following code to obtain your displacement:

 
 
  1. 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!

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.