IOS development map and positioning, ios development map

Source: Internet
Author: User

IOS development map and positioning, ios development map

Positioning is indispensable for both QQ and mobile clients. The positioning function was not added in the demo. Today, I will write a location demo to learn about positioning and map. Maps and positioning seem to be very tall. In fact, the usage is much simpler than TableView. The Demo below uses the map and positioning in iOS, of course, you can also use a third party to load maps, such as Baidu maps. Today's blog mainly introduces the use of MKMapView. MapView is similar to other components. MapView uses delegate callback and implements the MKMapViewDelegate protocol in the Controller of mapView, register the delegate callback and implement the corresponding callback method.

 

I. Build Demo Components

To save time, MapView in this demo is dragged out by Storyboard. The structure of the storyboard is as follows. MKMapView is used to display the map. The labei below is used to display the current longitude and latitude:

 

3. Compile the annotation module class

1. First, explain what the labeling module is: the labeling module displays information about the current geographical location. The following figure shows the labeling module in the green box:

  

  

2. Compile the annotation class. The annotation class must implement the MKAnnotation protocol. The code in MyAnnotation. h is as follows:

  

3. Implement the method in the MyAnnotation protocol. titile returns the title and subTitle, and the code is as follows:

4. Compile the code in ViewController

1. In ViewController. h, introduce the corresponding package and implement the corresponding protocol Code as follows:

3. Implement the annotation view in the delegate callback. The Code is as follows:

 

4. Obtain the geographic location information. The Code is as follows:

1 // method in implementation protocol get coordinate 2-(void) mapView :( MKMapView *) mapView didUpdateUserLocation :( MKUserLocation *) userLocation 3 {4 // get location 5 CLLocation * location = userLocation. location; 6 7 // obtain the longitude and latitude 8 CLLocationCoordinate2D coordinate = location through location. coordinate; 9 10 11 // display latitude and longitude 12 [self mapPoint: coordinate]; 13 14 15 // mark range: 16 MKCoordinateSpan span; 17 span. latitudeDelta = 0.1; 18 span. longitudeDelta = 0.1; 19 MKCoordinateRegion region = {coordinate, span}; 20 21 [self. myMapView setRegion: region]; 22 23 24 25 _ block _ weak ViewController * copy_self = self; 26 27 // resolution location 28 CLGeocoder * geocoder = [[CLGeocoder alloc] init]; 29 [geocoder reverseGeocodeLocation: location completionHandler: ^ (NSArray * placemarks, NSError * error) {30 if (placemarks. count> 0) {31 // use CLPlacemark to parse the geographic location 32 CLPlacemark * placeMark = placemarks [0]; 33 NSDictionary * addressDictionary = placeMark. addressDictionary; 34 35 36 // Add map annotation 37 MyAnnotation * annotation = [[MyAnnotation alloc] init]; 38 annotation. subTitle = addressDictionary [@ "Name"]; 39 annotation. coordinate = coordinate; 40 41 // Add annotation information 42 [copy_self.myMapView addAnnotation: annotation]; 43} 44}]; 45 46}View Code

 

The above is all the Demo code, and the following is the running:

 


In ios software development, you need to locate your location on the map to a designated road map. How should I write it?

Use AMAP SDK

IOS Baidu map locating

You have met me many times. 1. The network of the mobile phone may be unstable. 2. The mobile phone memory is insufficient. 3. The software is updated. 4. The system is unstable. I used to solve these three problems in 1.3.4.

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.