iOS Development map and location

Source: Internet
Author: User

Whether it is QQ or mobile client will not have to locate the function, before in the demo did not join the positioning function, today, write a positioning of the small demo to understand the positioning and map things. Maps and positioning seem to be quite tall on a thing, and its use is much simpler than tableview. The following demo is the use of the iOS with the map and positioning, of course, you can also use a third party to load the map, such as Baidu map what. Don't dwell on it here.

Today's blog is mainly about the use of Mkmapview. The use of Mapview and the use of other components is almost the same, Mapview with the trust callback, in the use of Mapview controller to implement the Mkmapviewdelegate protocol, and register the trust callback, and then implement the corresponding callback method can be.

One, build the components of the demo

In order to save time the Mapview in this demo is dragged out by storyboard, and the structure in the storyboard is seen in the following example. Above is the Mkmapview used to display the map. The following labei are used to display the current latitude and longitude:

Second, the introduction of Mkmapview to use the package. For example, the following:

Third, the class to write the labeling module

1. First explain what the labeling module is: The callout module is the information that displays the current location, in the green box is the callout module:

  

  

2. Write the Label class. The callout class must implement the Mkannotation protocol, the code in MyAnnotation.h such as the following:

  

3. Implement the method in protocol Myannotation, Titile returns the title, subtitle is a sub-title. The code is as follows:

Iv. writing code in the Viewcontroller

1.viewcontroller.h to introduce the corresponding package and implement the corresponding protocol code such as the following

2. Write the code in the VIEWCONTROLLER.M to implement the corresponding trust callback method in the protocol. The extension and initialization methods in M are as follows

3. Implement the callout view in the commit callback, such as the following code:

4. Get geo-location information. The code is as follows:

View Code

The above is the entire demo code, the following is performed:

iOS Development map and location

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.