iOS Development corelocation (i)

Source: Internet
Author: User

Introduction

In the era of mobile internet, mobile apps can solve many of the user's life chores, such as

Navigation: Go to any unfamiliar place

Nearby: Find a restaurant, find a hotel, find a bank, find a cinema

In the above applications, maps and positioning functions are used , in IOS development, in order to join the 2 major functions, must be based on 2 frameworks for development

Map Kit : for maps

Core location: for geolocation

2 Hot Technical terms

LBS : LocationBased Service

SoLoMo :social Local Mobile(Solomon)

use of the corelocation framework

Corelocation Framework Usage Prerequisites

Import Frame

Import Primary header file

#import <CoreLocation/CoreLocation.h>

Corelocation Framework Usage notes

the prefix for all data types in the Corelocation framework is CL

using Cllocationmanager objects in Corelocation to do user positioning

Cllocationmanager

common operations for Cllocationmanager

Start user targeting

1 -(void) startupdatinglocation;

Stop user Targeting

1 -(void) stopupdatinglocation;

How many meters to locate each time

1 @property (Assign, nonatomic) cllocationdistance distancefilter;

Positioning accuracy (the more accurate it consumes)

1 @property (Assign, nonatomic) cllocationaccuracy desiredaccuracy;

when the startupdatinglocation method is called, the user's location is started constantly, and the agent's method is called frequently in the middle

1 -(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations;

The locations parameter contains the cllocation object .

cllocation

Cllocation The geographic information used to represent a location, such as latitude and longitude, altitude, etc.

Warp latitude

1 @property (readonly, nonatomic) cllocationcoordinate2d coordinate;

Elevation

1 @property (readonly, nonatomic) cllocationdistance altitude;

Course, course (Value range is 0.0°~ 359.9°,0.0° represents true North direction)

1 @property (readonly, nonatomic) Cllocationdirection course;

Walking Speed (unit is m/s)

1 @property (readonly, nonatomic) cllocationspeed speed;

with 1 -(cllocationdistance) Distancefromlocation: (const cllocation *) location method can calculate distance between 2 positions

cllocationcoordinate2d

Cllocationcoordinate2d is a structure used to represent latitude and longitude, defined as follows

1 struct {23         // Latitude 4 5         // Longitude 6 7 } cllocationcoordinate2d;

The Cllocationcoordinate2dmake function is generally used to create cllocationcoordinate2d

latitude and longitude degree

Prime Meridian

Through the Greenwenger Observatory in London

Go East (right), it's longitude (E)

Go West (to the left), it's longitude (W)

Everything 180°, total 360°

Equator

Go North (top), Latitude (N)

Go south (below), it's southern latitude (S)

South latitude 90°, total 180°

Across longitude \ latitude Greater (1°≈111km)

The greater the scope of the representation

The smaller the thing you see on the map.

latitude and longitude of China

Latitude and longitude range of celestial Kingdom

Latitude Range:n 3°51′~ N 53°33′

Longitude range:e 73°33′~ e 135°05′

Latitude and longitude of some cities in China

City

Longitude

Latitude

Beijing

E116°28 '

N39°54 '

Guangzhou

E113°15 '

N23°08 '

Chengdu

E104°05 '

N30°39 '

Shanghai

E121°29 '

N31°14 '

Shenzhen

E113°46 '

N22°27 '

Wuhan

E114°21 '

N30°37 '

Zhengzhou

E113°42 '

N34°48 '

Analog Location

If the simulator, you need to set the analog location (latitude and longitude)

The latitude and longitude of the Celestial Kingdom is: North latitude 40°, longitude 119°

Protection of user privacy

starting with IOS 6, Apple has done a great job of protecting the privacy of its users, and the following must be authorized by user approval

To get the user's location

Want to access users ' contacts, calendars, cameras, albums, and more

When you want to access the user's privacy information, the system will automatically pop up a dialog box to let the user authorize

Developers can set nslocationusagedescription in the Info.plist for the purpose of positioning (privacy-location Usage Description)

Once the user chooses "Don't allow", it means your app won't be able to use the targeting feature

For the sake of rigor, it's a good idea to determine if the current app's positioning function is available before using the location feature

Cllocationmanager has a class method to determine if the current app's positioning function is available

1 + (BOOL) locationservicesenabled;

Clgeocoder

Use clgeocoder to complete geocoding and anti-geocoding

Geocoding: Obtain specific location information (such as latitude and longitude, full name of address, etc.) based on a given place name

Anti-geocoding: Obtain specific location information based on a given latitude and longitude

Geo-coding methods

1 -(void) geocodeaddressstring: (NSString *) addressstring Completionhandler: ( Clgeocodecompletionhandler) Completionhandler;

Anti-geocoding methods

1 -(void) Reversegeocodelocation: (cllocation *) Location Completionhandler: ( Clgeocodecompletionhandler) Completionhandler;

Clgeocodecompletionhandler

when the local management \ Anti-geocoding is complete, the clgeocodecompletionhandler is called

typedef void (^clgeocodecompletionhandler) (nsarray *placemarks, nserror *error);

This block passes 2 parameters

Error : There is a value when the encoding is wrong (for example, no specific information is encoded)

Placemarks : It contains clplacemark objects .

Clplacemark

Clplacemark literally means a landmark, encapsulating detailed address location information

1 @property (nonatomic, readonly) cllocation *location;

Location

1 @property (nonatomic, readonly) clregion *region;

Regional

1 @property (nonatomic, readonly) nsdictionary *addressdictionary;

Detailed address information

1 @property (nonatomic, readonly) nsstring *name;

Address name

1 @property (nonatomic, readonly) nsstring *locality;

City

actual Combat

Lazy Loading method

1 -(Cllocationmanager *) lmgr2{3     if (_lmgr==nil) {  4         _lmgr = [[Cllocationmanager alloc] init]; 5         _lmgr. delegate = self ; 6         [_lmgr requestwheninuseauthorization]; 7     }8     return  _lmgr; 9 }

Listening location

1 -(void) viewdidload {2    [Super Viewdidload]; 3     // additional setup after loading the view, typically from a nib. 4     [Self.lmgr startupdatinglocation]; 5 }

To print location information in the agent method

1 -(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations2{3     NSLog (@ "%@", locations); 4 }

1 "<+39.11754092,+117.12951620> +/-65.00m (speed-1.00 mps/course-1.00) @ 15/2/ \u4e2d\u56fd\u6807\u51c6\u65f6\u95f410:19:19"

Latitude, longitude, altitude, speed, heading, time

Note: Use of corelocation in IOS8

Add two default fields to the Info.plist

    • Nslocationalwaysusagedescription

    • Nslocationwheninuseusagedescription

These are the prompts that are displayed in the Prompt box.

You need to call the method before using Corelocation

Requestwheninuseauthorization ()

Requestalwaysauthorization ()

As the name implies, one is the use of Peek User privacy, one is always peek user privacy

iOS Development corelocation (i)

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.