How to call Apple's own map navigation in iOS development

Source: Internet
Author: User

A period of time has been in the Rush project, in the outsourcing company work is commiseration, every day overtime do not say, work is tied to the duration of the contract, a little overdue may be deducted bonuses, do not talk about these nerve-racking things, let us talk about how to call the iOS development of the iphone's own map.

Study like riding, behind. The ancients told us to continue to reflect and summarize, day thinking is fine, moon thinking is fine, the year is fine. Only by constantly trying and summarizing can we make our work and life easier and happier and better. Connected to do two big mall outsourcing projects, Smart city, search pastoral pass, spent nearly four months of time, and finally in the perfect after repeated modification. During the difficulties from needless to say, after a lot of summing up and communication it. Baidu Map has been published before the use of an article, said very detailed, here is no longer involved, to the point, we say how to call Apple's own map.

First step: Import Map File #import <MapKit/MapKit.h>

Step two: Get the latitude and longitude of the current location and destination, then open the map

  

Get Current Location

Mkmapitem *mylocation = [Mkmapitem mapitemforcurrentlocation];

Current Warp dimension

float Currentlatitude=mylocation.placemark.location.coordinate.latitude;

float Currentlongitude=mylocation.placemark.location.coordinate.longitude;

Cllocationcoordinate2d coords1 = Cllocationcoordinate2dmake (currentlatitude,currentlongitude);

Destination location

Coordinate.latitude=[[datasource objectforkey:@ "lat"] floatvalue];

Coordinate.longitude=[[datasource objectforkey:@ "LNG"] floatvalue];

cllocationcoordinate2d coords2 = coordinate;

IOS6 below, call Google Map

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.longitude,coords2.latitude,coords2.longitude];

Nsurl *aurl = [Nsurl urlwithstring:urlstring];

Open a Web page Google Maps

[[UIApplication sharedapplication] openurl:aurl];

}

Else

Call the iOS own Apple map directly

{

The current location

Mkmapitem *currentlocation = [Mkmapitem mapitemforcurrentlocation];

Starting point

Mkmapitem *currentlocation = [[Mkmapitem alloc] Initwithplacemark:[[mkplacemark alloc] Initwithcoordinate:coords1 Addressdictionary:nil]];

Location of the destination

Mkmapitem *tolocation = [[Mkmapitem alloc] Initwithplacemark:[[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:mklaunchoptionsdirectionsmodedriving, Mklaunchoptionsmaptypekey: [NSNumber Numberwithinteger:mkmaptypestandard], Mklaunchoptionsshowstraffickey: @YES};

Open Apple's own map app and render a specific item

[Mkmapitem Openmapswithitems:items launchoptions:options];

}

  

Through these two steps can easily open the Apple with the map navigation, it feels really good, the only drawback is to open the map to get the route information consumed by mobile phone traffic is relatively large, preferably in the WiFi conditions called. If not must, as far as possible to use the gold or Baidu's own map is good.

How to call Apple's own map navigation in iOS development

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.