The following is just for understanding , The actual use of Baidu map is in the majority , Because Baidu map has dynamic path planning and other interfaces

MapKit Learning notes   

Original post : http://www.cocoachina.com/bbs/read.php?tid-66687-fpage-6.html

1、 summary
Insert MapView, Set up Delegate( It's usually Controller),Annotations Record interest locations (AnnotationView It's used to show the location of interest ),annotation It's optional , Selected annotation Will be displayed callout, Used to display information .
2、 Set the map display type :
mapView.mapType = MKMapTypeStandard;
mapView.mapType = MKMapTypeSatellite;
mapView.mapType = MKMapTypeHybrid; 
3、 Show user location
Set to display the user's location :
mapView.showsUserLocation = YES; 
Determine whether the user's current location is visible ( Read-only property ):
userLocationVisible 
Get the user's location coordinates : When userLocationVisible by YES when
CLLocationCoordinate2D coords = mapView.userLocation.location.coordinate; 
4、 Coordinate range
MKCoordinateRegion Used to set the coordinate display range .
It consists of two parts :Center(CLLocationCoordinate2D struct, Include latitude and longitude), Coordinate center
and Span(MKCoordinateSpan struct, Include latitudeDelta and longitudeDelta), Zoom level
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(center,2000, 2000); 
The above code creates a center Centered , Up and down 1000 rice , Around the 1000 The Mead area , But it's a rectangle , Do not conform to the MapView The ratio of horizontal to vertical
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion]; 
The above code creates one that conforms to MapView The area of horizontal and vertical proportions
[mapView setRegion:adjustedRegion animated:YES]; 
The above code is : The final display of the area
5、Delegate
Use MapView Must comply with MKMapViewDelegate agreement
5.1、 Map loading Delegate
When needed Google When the server gets a new map
mapViewWillStartLoadingMap: 
When the map is successfully obtained
mapViewDidFinishLoadingMap: 
When you fail to get the map ( It is recommended that at least this approach be implemented )
mapViewDidFailLoadingMap:withError:

5.2、 Range change Delegate
When the gesture starts ( Drag and drop , Zoom in , narrow , double-click )
mapView:regionWillChangeAnimated: 
When the gesture is over ( Drag and drop , Zoom in , narrow , double-click )
mapView:regionDidChangeAnimated: 
Determine if the coordinates are in MapView Within the display range :
CLLocationDegrees leftDegrees = mapView.region.center.longitude –(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightDegrees = mapView.region.center.longitude +(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees bottomDegrees = mapView.region.center.latitude –(mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = self.region.center.latitude +(mapView.region.span.latitudeDelta / 2.0);
if (leftDegrees > rightDegrees) { // Int'l Date Line in View
leftDegrees = -180.0 - leftDegrees;
if (coords.longitude > 0) // coords to West of Date Line
coords.longitude = -180.0 - coords.longitude;
}
If (leftDegrees <= coords.longitude && coords.longitude <= rightDegrees && bottomDegrees <= coords.latitude && coords.latitude <= topDegrees) {
   // The coordinates are in range
}

6、Annotation
Annotation It has two parts :Annotation Object and Annotation View
Annotation Object It has to comply with the agreement MKAnnotation, There are two ways :title and subtitle, Used to display the title and subtitle of the comment, respectively . also coordinate attribute , return CLLocationCoordinate2D, Express Annotation The location of
then , Need to use mapView:viewForAnnotation:  Method to return MKAnnotationView perhaps MKAnnotationView Subclasses of are used to display Annotation( Be careful : It's not the selection that's shown here Annotation Pop up box after ) 
You can subclass MKAnnotationView, And then again drawRect: Method to draw your own action ( It's a stupid method )
You can instantiate one MKAnnotationView, Then change its image attribute , It's easy .

7、 Add remove Annotation
Add one Annotation
[mapView addAnnotation:annotation]; 
Add one Annotation Array
[mapView addAnnotations:[NSArray arrayWithObjects:annotation1, annotation2, nil]]; 
Remove a Annotation
removeAnnotation: 
Remove a Annotation Array
removeAnnotations: 
Remove all Annotation
[mapView removeAnnotations:mapView.annotations];

8、 Choose Annotation
There can only be one at a time Annotation To be selected , When selected, it will appear CallOut( Floater )
ordinary CallOut Show Title and SubTitle, But you can also customize one UIView As CallOut( With custom TableViewCell equally )
It can be selected by code Annotation:
selectAnnotation:animated: 
Or deselect :
deselectAnnotation:animated:

9、 Show Annotation
adopt mapView:viewForAnnotation:  Method display Annotation, Every time MapView Add a Annotation, This method will be called
Example ( And tableView:cellForRowAtIndexPath:  Very similar )

- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>) annotation {
static NSString *placemarkIdentifier = @"my annotation identifier";
if ([annotation isKindOfClass:[MyAnnotation class]]) {
     MKAnnotationView *annotationView = [theMapView dequeueReusableAnnotationViewWithIdentifier:placemarkIdentifier];
if (annotationView == nil) {
         annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:placemarkIdentifier];
annotationView.image = [UIImage imageNamed:@"blood_orange.png"];
}
else
annotationView.annotation = annotation;
return annotationView;
}
return nil;
}

10、 Get the real address
Example :
initialization MKReverseGeocoder

MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinates];
geocoder.delegate = self;
[geocoder start]; 
If you can't handle coordinates , Call reverseGeocoder:didFailWithError:  Method

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
NSLog(@"Error resolving coordinates: %@", [error localizedDescription]);
geocoder.delegate = nil;
[geocoder autorelease];

If it works , Call reverseGeocoder:didFindPlacemark:  And store the information in MKPlacemark  in
didFindPlacemark:(MKPlacemark *)placemark {
NSString *streetAddress = placemark.thoroughfare;
NSString *city = placemark.locality;
NSString *state = placemark.administrativeArea;
NSString *zip = placemark.postalCode;
// Do something with information
geocoder.delegate = nil;
[geocoder autorelease];
}

Leonbao:MapKit Learn more about notes

  1. iOS Learning notes - Map MapKit introduction

    The code address is as follows :http://www.demodashi.com/demo/11682.html This article is still translated from raywenderlich, use Objective-C Rewriting the code . No word for word translation , Any errors ...

  2. iOS Learning notes 20- Map ( Two )MapKit frame

    One . Introduction to map development from iOS6.0 At first, map data is no longer driven by Google , Instead, use your own map , Of course, in China, its data is provided by Gaud map . stay iOS There are three main ways to develop maps in : utilize MapKit Framework for map development , Use this ...

  3. iOS Learning notes - Essence finishing

    iOS Summary and arrangement of study notes One . Memory management 1- autorelease, When the user's code is running continuously , Automatic release pools are not destroyed , During this time, users can safely use automatically released objects . When the user's code comes to an end fall , Start ...

  4. iOS Summary and arrangement of study notes

    source :http://mobile.51cto.com/iphone-386851_all.htm Study IOS Develop this for a beginner , It's a very head scratching thing . In fact, learning IOS Development is nothing more than usual accumulation and summary . Next ...

  5. js Learning notes :webpack Basic introduction ( One )

    I've heard of it before webpack, I'd like to have a formal contact with you today , Follow first webpack The official user's Guide to go : Here is : How to install webpack How to use webpack How to use loader How to use webpack The developer of the ...

  6. PHP- Custom template - Learning notes

    1.  Start This few days , After reading teacher Li Yanhui's <PHP Second quarter video > Medium “ chapter 7: establish TPL Custom template ”, Make a study note , By drawing the architecture diagram .UML Class diagrams and mind maps , To better understand . 2.  Overall architecture ...

  7. PHP- Member login and registration example analysis - Learning notes

    1. Start Recently I began to learn from Mr. Li Yanhui <PHP Second quarter video > Medium “ chapter 5: Use OOP Registered members ”, Make a study note , By drawing the basic page flow and UML Class diagram , To better understand . 2. Basic page flow 3. adopt UM ...

  8. 2014 Summer vacation c# A list of study notes

    2014 Summer vacation c# Learning notes One .C# Programming based 1. c# Enumeration of programming basics 2. c# Function variable parameters of programming basis 3. c# String basis of programming basis 4. c# String function of programming basis 5.c# Fundamentals of programming ref.ou ...

  9. JAVA GUI Programming learning notes Directory

    2014 Summer vacation JAVA GUI Programming learning notes Directory 1.JAVA And GUI Programming overview 2.JAVA And GUI Programming layout 3.JAVA And GUI Programming Frame window 4.JAVA And GUI Programming event monitoring mechanism 5.JAVA And ...

Random recommendation

  1. inline js Function call

    <ul> <li onclick=abc(this);><a href="javascript:void(0);">12234588</a ...

  2. centos 7 install mysql

    # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community- ...

  3. HDU 5120 Intersection(2014 Live competition in Beijing I topic Computational geometry )

    Topic link :http://acm.hdu.edu.cn/showproblem.php?pid=5120 Problem solving report : Give you two identical rings , I want you to find out the area of the part where these two rings intersect ? I haven't understood the meaning of the title for a long time . ring ...

  4. DedeCMS The full version of Tongsha SQL Inject exploit code

    EXP: Exp:plus/recommend.php?action=&aid=1&_FILES[type][tmp_name]=\'   or mid=@`\'` /*!50000u ...

  5. C# Multithreading Simple usage and common parameters

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. Delphi TcxTreeList Nodes add pictures

    Need to give TcxTreelist Add pictures to the columns of , The operation is as follows 1. Set Columns , Set up Properties by ImageComboBox , 2. Set up Properties -> Items Add content The corresponding increase ...

  7. ubuntu Lower installation tomcat And configuration mysql

    1. To the official website  http://jakarta.apache.org/tomcat-7.0.2.tar.gz The installation files ,JDK Suppose it's installed , Next, install it directly tomcat-7.0.2.tar.gz # ls ...

  8. 201521123098 《Java Programming 》 The first 7 Weekly learning summary

    1. This week's learning summary In the way you like ( Mind mapping or something ) Summarize the relevant contents of the collection . 2. Written work 1. ArrayList The code analysis 1.1 explain ArrayList Of contains Source code This method calls ind ...

  9. jmeter Test tutorial

    http://www.cnblogs.com/TankXiao/p/4045439.html

  10. Bellman-Ford Find the shortest path with negative weight

    For a detailed explanation of the algorithm, please see   https://www.cnblogs.com/tanky_woo/archive/2011/01/17/1937728.html Single source shortest path   When there are negative weight edges in a graph Dijkstra just ...