In ios development, how does one call Apple's built-in map navigation?
I have been working on projects for some time ago. I am hard at work in outsourcing companies. If I work overtime every day, my work is linked to the construction period contract. If I am a little late, I may be deducted for a bonus, let's talk about how to call the map that comes with Apple's mobile phone in iOS development.
Learning is like sailing against the water. If you do not enter, you will leave. The ancients told us that we should constantly reflect on and summarize things, such as daily thinking, daily thinking, and monthly thinking. Only by constantly trying and summing up can we make our work and life more pleasant and beautiful. It took nearly four months to complete two major mall outsourcing projects, smart cities, and soumu Tong. I don't have to mention the difficulties in the period. I will summarize and communicate more in the future. I have published an article about the use of Baidu map, which is very detailed. I will not discuss it here. Let's get down to it. Let's talk about how to call the map that comes with Apple.
Step 1: import the map file # import <MapKit/MapKit. h>
Step 2: Obtain the longitude and latitude of the current location and destination, and then open the map.
// Obtain the current location
MKMapItem * mylocation = [MKMapItem mapItemForCurrentLocation];
// Current dimension
Float currentLatitude = mylocation. placemark. location. coordinate. latitude;
Float currentlongpolling = mylocation. placemark. location. coordinate. longpolling;
CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake (currentLatitude, currentlong.pdf );
// Destination location
Coordinate. latitude = [[dataSource objectForKey: @ "lat"] floatValue];
Coordinate. longpolling = [[dataSource objectForKey: @ "lng"] floatValue];
CLLocationCoordinate2D coords2 = coordinate;
// Call google map below ios6
If (SYSTEM_VERSION_LESS_THAN (@ "6.0 "))
{
NSString * urlString = [[NSString alloc] initWithFormat: @ "http://maps.google.com/maps? Saddr = % f, % f & daddr = % f, % f & dirfl = d ", coords1.latitude, coords1.longdistance, coords2.latitude, coords2.longdistance];
NSURL * aURL = [NSURL URLWithString: urlString];
// Open the webpage, google Map
[[UIApplication sharedApplication] openURL: aURL];
}
Else
// Directly call the apple map provided by ios
{
// Current location
MKMapItem * currentLocation = [MKMapItem mapItemForCurrentLocation];
// Start point
// MKMapItem * currentLocation = [[MKMapItem alloc] initwit2d-acemark: [[MKPlacemark alloc] initWithCoordinate: coords1 addressDictionary: nil];
// Location of the destination
MKMapItem * toLocation = [[MKMapItem alloc] initwithzacemark: [[MKPlacemark alloc] initWithCoordinate: coords2 addressDictionary: nil];
ToLocation. name = @ "destination ";
NSString * myname = [dataSource objectForKey: @ "name"];
If (! [XtomFunction xfunc_check_strEmpty: myname])
{
ToLocation. name = myname;
}
NSArray * items = [NSArray arrayWithObjects: currentLocation, toLocation, nil];
NSDictionary * options =@{ MKLaunchOptionsDirectionsModeKey: Keys, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger: MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey: @ YES };
// Open the apple map application and present a specific item
[MKMapItem openMapsWithItems: items launchOptions: options];
}
In these two steps, you can easily enable Apple's built-in map navigation, which is really good. The only drawback is that it takes a lot of mobile phone traffic to enable the map to obtain route information, it is best to call it under wifi conditions. If not necessary, try to use the map provided by AMAP or Baidu.