Implementation of the iOS map Navigator

Source: Internet
Author: User

The first part of the Knowledge reserve

1 Location based on address

Apple provides the developer with the Clgeocode tool class for address resolution, which resolves the address entered by the user into latitude and longitude, which is:

-geocodeaddressstring:d estaddress completionhandler: ^ (nsarray *placemarks, nserror *error) This method will parse the string address, then you can get the corresponding latitude and longitude


2 Mkmapview controls and related properties


<1 iOS Mkmapview supports three types of properties:

Mkmaptypestandard = 0, Standard

Mkmaptypesatellite, Satellite cloud

Mkmaptypehybrid, mixed


<2 properties of three Boolean types: Zoomenable Zoom property, rotateenable rotation property, scrollenable scrolling property

<3 Showuserlocation This property can be used to display the current user's location

3 Proxy method for Mkmapview

This program overrides the-mapview:rendererforoverly method, and its return value is our navigation route. In this method the Mkoverlay protocol is used, which is used to represent the covering layer. The drawing line here uses one of its implementation classes: Mkpolylinerenderer, he stands for the navigation route of the car's walk. And it is inherited from Mkoverlayrenderer. You have both the fill color strokecolor and the LineWidth line width properties. For other properties, you can view its official documentation.

4 Getting the navigation route

<1 uses Mkdiretionsrequest to create a request navigation object, set the starting point.

<2 sets the target point, which is used to create the request initialization mkdirections.

<3 Call mkdirection method-calculatedirectioswithcompletionhandler, get navigation route

5 iOS maps Common English Vocabulary summary and its interpretation

<1 cllocation: Package location information, etc. (latitude, longitude, altitude, etc.)

<2 Clplacemark: Used to indicate a detailed location, such as the name of the place, city name, country, street, zip code, etc.

<3 mkuserlocation: Used to encapsulate pin position information (such as title, sub-title) on the map

<4 cllocationdegrees: Degrees of latitude and precision are encapsulated

<5 cllocationcoodinate2d: encapsulating geographic coordinates (e.g. cllocationdegrees latitude cllocationdegrees longitude)

<6 mkcoodinatespan: expression span (longitude span: cllocationdegrees Longitudedelta latitude span cllocationdegrees latitude)

<7mkcoodinateregion: Zone (Central cllocationcoodinate2d Center area span Mkcoodinatespan span)

The second part of the program implementation ideas (that is, pseudo-code)


Part III UI setup

1 Drag a Uitextfield as the user enters the destination container

2 Drag a mkmapview used as the display map

3 Defining a property to hold the navigation path

@property(nonatomic,strong) mkpolyline* navigationpath;

4 Creating an address resolver by lazy loading

5 drag in a button to implement user click events

6 UI interface to build the connection as follows:


The fourth part of the Virtual keyboard processing


part fifth dealing with the location of the program simulator

Sometimes when we enter the program for the second time, we find that our position on the simulator is not shown, which requires us to give the simulator a location.

Check simulator ———— "Debug ————" location ———— "Custom Position ————" Enter your current location of latitude and longitude ———— "select OK.

part sixth writing code

The code is as follows:

part Seventh procedure

Implementation of the iOS map Navigator

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.