iOS Learning--MAP 2 tracks user location changes

Source: Internet
Author: User

Welcome reprint, Reprint please indicate the source

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


Review
Mapkit provides an API to track changes in user location and direction, so we don't need to customize edit positioning information here to the system.
Add Framework
Implementing authorization to get location information
In
iOS8, no user authorization program is able to obtain location information, so we need to add two key values on the Info.plist:

Nslocationalwaysusagedescription

Nslocationwheninuseusagedescription

Add Cllocationmanager type properties to self (viewcontroller) at the same time

#import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import <corelocation/cllocationmanagerdelegate.h > @interface viewcontroller:uiviewcontroller@property (Weak, nonatomic) Iboutlet Mkmapview *mapview; @property ( strong,nonatomic) Cllocationmanager *locationmanage;

then implement the request authorization method:

    Self.locationmanage=[cllocationmanager new];    [Self.locationmanage requestalwaysauthorization];

There are two ways to request authorization:

Requestalwaysauthorization always authorizes

Requestwheninuseauthorization when trying to authorize

effect after implementation: (user allows you to get location information)
Implementation tracking
How to set up tracking
    if ([Cllocationmanager locationservicesenabled])    {        mapview.maptype=mkmaptypestandard;        mapview.delegate=self;        Mapview.showsuserlocation=yes;        [Mapview setusertrackingmode:mkusertrackingmodefollow animated:yes];//set tracking mode    }
There are three ways to track your options.

Mkusertrackingmodenone does not track

Mkusertrackingmodefollow Tracking

Mkusertrackingmodefollowwithheading tracking to get location information and direction information

location information for real-time update tracking
Mkusertrackingmodenone = 0,//the user's location was not followedmkusertrackingmodefollow,//The map follows the user ' s Locationmkusertrackingmodefollowwithheading,

Look at the effect: isn't it cool? But: is the range a little bit bigger?


Set Display range (region)Add the following code:
        Mkcoordinateregion viewregion=mkcoordinateregionmakewithdistance (mapview.centercoordinate, +, +);            [Mapview setregion:viewregion Animated:yes];
The first line of code sets three parameter meanings: Origin, North and south, things See: iOS Learning--MAP 1 show map + reality map
look at the final effect:

OS Learning-Location Services 4 setting test location Debug Test location



Source:

Https://git.oschina.net/zhengaoxing/No15.2.2follow



iOS Learning-MAP 2 Tracking user location changes

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.