iOS Development map and location

Source: Internet
Author: User

Whether it is QQ or mobile clients do not have to locate the function, before in the demo did not add positioning function, today write a small demo to find out the location and map of things. Map and positioning seems to be quite tall on a thing, in fact, the usage is much simpler than TableView, the following demo is used in the iOS with the map and positioning, of course, you can also use a third-party to load maps, such as Baidu Map What, in this do not repeat. Today's blog is mainly about the use of Mkmapview, the use of Mapview and other components of the usage of the same, Mapview with a delegate callback, in the use of Mapview controller to implement the Mkmapviewdelegate protocol, and register the delegate callback, and then implement the corresponding callback method.

One, build the components of the demo

To save time the Mapview in this demo is dragged out with storyboard, the structure in storyboard is shown below, Mkmapview is used to display the map, and the following labei is used to display the current latitude and longitude:

Second, the introduction of Mkmapview to use the package, as follows:

Third, the class to write the labeling module

1. First explain what the labeling module is: The callout module is the information showing the current location, the following green box is the callout module:

  

  

2. Write the callout class, the callout class must implement the Mkannotation protocol, the code in the MyAnnotation.h is as follows:

  

3. Implement the method in the protocol myannotation, Titile returns the title, subtitle is the 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 as follows

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

3. Implement the callout view in the delegate callback, with the following code:

4. Get geo-location information with the following code:

View Code

The above is the demo of all the code, the following is run:

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.