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. It is much simpler to use than the TableView. The following demo is a map and location that comes with iOS and, of course, the ability to load a map with a third party. For example, Baidu Map What, in this will not repeat. Today's blog is mainly about the use of Mkmapview. The use of Mapview and other components is almost identical. Mapview with the trust callback, in the use of Mapview controller to implement the Mkmapviewdelegate protocol, and the Register entrusted callback, and then implement the corresponding callback method can be.
One. Building a Demo component
In order to save time the Mapview in this demo is dragged out by storyboard, and the structure in the storyboard is shown below, Mkmapview is 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, such as 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. Writing the callout class, the callout class must implement the Mkannotation protocol. The code in MyAnnotation.h such as the following:
3. Implement the method in the protocol myannotation, Titile returns the title, subtitle is the sub-title, code such as the following:
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, and the extension and initialization methods in. m for example, the following
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:
Maps and positioning in iOS development