iOS Learning--MAP 3 Call Apple Maps

Source: Internet
Author: User

Welcome reprint, Reprint please indicate the source

This address: http://blog.csdn.net/zhenggaoxing/article/details/42710853

Review:
the Apple map call here refers to the jump from our software to the Apple map, we have to do is to set up the data, in the use of Apple Maps can be
Show a dot on the Apple map
Add the relevant framework
we're going to show a point on the Apple map, what do we need? 1 need location, 2 need location-related information. With these two messages, you can.
 Clgeocoder *geocoder=[clgeocoder new]; Use geo-information anti-coding to get location and information [Geocoder geocodeAddressString:textQueryTextField.text completionhandler:^ (Nsarray *        Placemarks, Nserror *error) {NSLog (@ "Number of query records:%i", (int) [placemarks count]);                        if ([Placemarks count]>0) {Clplacemark *placemark=placemarks[0];            Cllocationcoordinate2d coordinate=placemark.location.coordinate;                        Nsdictionary *address=placemark.addressdictionary; Mkplacemark is a map-related information class Mkplacemark *place=[[mkplacemark alloc]initwithcoordinate:coordinate/* location */addressDict                        ionary:address/* Related information */];            The Mkmapitem class encapsulates information about points on the map Mkmapitem *mapitem=[[mkmapitem Alloc]initwithplacemark:place];                        Method of calling Apple Maps [Mapitem Openinmapswithlaunchoptions:nil];        [Textquerytextfield Resignfirstresponder]; }    }];
To explain: 1 gets location information (clplacemark) 2 pass location and information to map (Mkplacemark) 3 call Apple Map (Openinmapswithlaunchoptions method)
Effect:

Show Route
The route shown here is from the location of the mobile phone to the route you want to go to, showing the route more than a point to be set: what way to go to that point
            Set driving directions on the map            nsdictionary* options =[[nsdictionary Alloc]initwithobjectsandkeys:                                    Mklaunchoptionsdirectionsmodedriving,mklaunchoptionsdirectionsmodekey, nil];                        Mkmapitem *mapitem = [[Mkmapitem alloc]initwithplacemark:place];            [Mapitem openinmapswithlaunchoptions:options];
Here's an explanation:
How to set it up: With the nsdictionary type parameter setting,

set driving route:
Mklaunchoptionsdirectionsmodedriving has two key values:

mklaunchoptionsdirectionsmodedriving--Driving

mklaunchoptionsdirectionsmodewalking--Bike


There are several key settings:

Mklaunchoptionsmaptypekey: Setting the map type

Mklaunchoptionsshowstraffickey: Setting Traffic conditions

Mklaunchoptionsmapcenterkey: Setting the Map Center

Mklaunchoptionsmapspankey: Setting map spans

Look at the effect


Show multiple points on the Apple map
Show multiple points, implemented using the Openmapswithitems method: Loading an array can
    Clgeocoder *geocoder = [[Clgeocoder alloc] init];                                                                         [Geocoder geocodeAddressString:self.textTextField.text completionhandler:^ (nsarray                *placemarks, Nserror *error) {NSLog (@ "Query Record Count:%i", (int) [placemarks count]);                nsmutablearray* array = [Nsmutablearray new];                        for (int i = 0; i < [Placemarks count]; i++) {clplacemark* placemark = placemarks[i];            cllocationcoordinate2d coordinate = placemark.location.coordinate;                        nsdictionary* address = placemark.addressdictionary; Mkplacemark *place = [[Mkplacemark alloc] Initwithcoordinate:coordinate addressdictionary                        : Address];                        Mkmapitem *mapitem = [[Mkmapitem alloc]initwithplacemark:place];        [Array Addobject:mapitem]; }//Turn off the keyboard [Self.texttextfield ResignfirstResponder];        if ([array count] > 0) {[Mkmapitem openmapswithitems:array launchoptions:nil]; }    }];
Look at the effect



Source code:

Https://git.oschina.net/zhengaoxing/No15.3appleMap/tree/master






















iOS Learning--MAP 3 Call Apple Maps

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.