Map Little Notes

Source: Internet
Author: User

Corelocation geo-Location Map Kit Map Show

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 to find restaurants around the hotel, find a bank, to find the cinema in the above applications are used in the Map positioning function, in iOS development want to join these 2 major features must be based on 2 frameworks to develop the map Kit Used for map display core location for map display  2 Popular professional terms lbs location Based Servicesolomo Social Local mobile  Corelocation Framework use Corelocation Framework usage Prerequisites   Import Master header file #import<corelocation/corelocation.h >corelocation framework use The prefix of all data types in the  corelocation framework is the common operation for user targeting Cllocationmanager using Cllocationmanager objects in clcorelocation   start user positioning- (void) startupdationglocation; Stop user positioning-(void) stopupdatinglocation; When the Startupdatinglocation method is called, the user's position is constantly located. The following method of calling the agent frequently-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations;  The locations parameter contains Cllocation object clllocation used to represent geographic information for a location, such as latitude and longitude, elevation, etc.   @Property (readonly, nonatomic) cllocationcoordinate2d coordinate; by Latitude @property (readonly, nonatomic) cllocationdistance altitude; Elevation @property (readonly, nonatomic) Cllocationdirection course, course, course (value range is 0.0~359.9,0.0 for True North) @property (ReadOnly, nonatomic) cllocationspeed speed; Travel speed with-(CllocationdiStance) Distancefromlocation: (const cllocation *) Location above the method can calculate the distance between 2 locations @property (assign, nonatomic) Cllocationdistance distancefilter; Locate @property (Assign, nonatomic) cllocationaccuracydesireaccuracy every few meters; Positioning accuracy (the more accurate it consumes)  cllocationcoordinate2d is a structure that represents the latitude and longitude, defined as follows TYPEDF struct { cllocationdegrees latitude;// Latitude cllocationdegrees longitide;//longitude   } Cllocationcoodinate2d generally use the Cllocationcoordinate2dmake function to create cllocationcoordinate2d if the simulator needs to set the analog location (latitude and longitude) from iOS 6 Beginning Apple has done a great job in protecting privacy, and the operation must be approved by the user to obtain the user's location Dangxiang privacy information for anti-access, the system pops up a dialog box to allow users to authorize   Developers can set nslcationusagedescription instructions (privacy-location Usage Description) in Info.plist once the user selects the dot Allow for the positioning of your app is not available for the sake of rigor, it is best to determine if the current positioning function can be used before using the positioning function Cllocationmanager has a class method to determine if the current application's positioning function is available + (BOOL) locationservicesenable; Clgeocoder uses Clgeocoder to accomplish geocoding and geo-coding geocoding. According to the given place name, obtain the specific location information (such as the full name of the latitude and longitude address) the anti-address code according to the given latitude and longitude, obtain the specific location information geocoding Method-(void) geocodeaddressstring: (NSString *) Addressstring Completionhandler: (clgeocodecompletionhandle) Completionhandler; anti-Address encoding Method-(void) ReversegeOcodelocation: (cllocation *) location Completionhandler: (Clgeocodecompletionhandler) completionhandler;    Local manager, when anti-geocoding is complete, clgeocodecompletionhandler typedef void (^clgeocodecompletionhandler) is called (Nsarray *placemarks, Nserror *error); This block passes 2 parameter error when the code error (such as the code does not have specific information) has a value placemarks inside the object containing the Clplacemark Clpacemark literally means a landmark, Encapsulates the detailed address location information @property (nonatomic, readonly) cllocation *location; Location @property (nonatomic, readonly) clregion *region; area @property (Nonatomic, readonly) nsdictionary *addressdictionary ; Detailed address information @property (nonatomic, readonly) nsstring *name; address name @property (nonatomic, readonly) NSString *locality; City   Mapkit Framework use Mapkit framework of Use Prerequisites Import Framework mapkit.framework  Import header file <MapKit/MapKit.h> Mapkit Framework usage Mapkit All data type prefixes in the framework are mkmapkit have a more important UI control: Mkmapview, specifically for map display, The trace displays the user's location settings Mkmapview Usertrackingmode property can track the current location of the user Mkusertrackingmodenone does not track the user's location   Mkusertrackingmodefollow track and display the user's current location on the graph mkusertrackingmodefollowwithheading track and display the user's current location on the map the map will be rotated at any time following the user's forward direction by setting the MKMAPV Iew Mapviewtype Setting the map type    iosbird  9 hours ago   ios technology |    Grab sofa  3  article score 0  times, average score of 0.0  :     

Here is a summary of the map positioning knowledge. Corelocaton,map Kit.

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:location Based Service

Solomo:social Local Mobile (Solomon)

Use of the Corelocation framework

Corelocation Framework Usage Prerequisites

Import Frame Corelocation

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

Common operations for Cllocationmanager

Start user targeting

-(void) startupdatinglocation;

Stop user Targeting

-(void) stopupdatinglocation;

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

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

The locations parameter contains the Cllocation object.

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

@property (readonly, nonatomic) Cllocationcoordinate2d coordinate; Warp latitude

@property (readonly, nonatomic) cllocationdistance altitude; Elevation

@property (readonly, nonatomic) Cllocationdirection course;

Course, course (value range is 0.0°~ 359.9°,0.0° represents true north direction)

@property (readonly, nonatomic) cllocationspeed speed;

Travel speed (unit m/s)

With-(cllocationdistance) Distancefromlocation: (const cllocation *) Location

The above method can calculate the distance between 2 positions

@property (Assign, nonatomic) cllocationdistance distancefilter;

How many meters to locate each time

@property (Assign, nonatomic) cllocationaccuracy desiredaccuracy;

Positioning accuracy (the more accurate it consumes)

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

typedef struct {

Cllocationdegrees latitude; Latitude

Cllocationdegrees longitude; Longitude

} cllocationcoordinate2d;

The Cllocationcoordinate2dmake function is generally used to create cllocationcoordinate2d

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

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 instructions for positioning in Info.plist (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

+ (BOOL) locationservicesenable;

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

-(void) geocodeaddressstring: (NSString *) addressstring Completionhandler:

(Clgeocodecompletionhandler) Completionhandler;

Anti-geocoding methods

-(void) Reversegeocodelocation: (cllocation *) Location Completionhandler:

(Clgeocodecompletionhandler) Completionhandler;

When Geo-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

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

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

@property (nonatomic, readonly) nsdictionary *addressdictionary; Detailed address information

@property (nonatomic, readonly) NSString *name; Address name

@property (nonatomic, readonly) NSString *locality; City

Use of the Mapkit framework

Mapkit Framework Usage Prerequisites

Import Frame Mapkit.framework

Import Primary header file

#import <MapKit/MapKit.h>

Mapkit Framework Usage Notes

The prefix for all data types in the Mapkit framework is MK

Mapkit has a more important UI control: Mkmapview, specifically for map display

Trace displays the user's location

Set the Usertrackingmode property of Mkmapview to track the current location of the user

Mkusertrackingmodenone: Do not track the user's location

Mkusertrackingmodefollow: Track and display the user's current location on the map

Mkusertrackingmodefollowwithheading: Tracks and displays the user's current location on the map, which rotates with the user's forward direction

Type of Map

You can set the map type by setting the Mapviewtype of Mkmapview

Mkmaptypestandard: General Map

Mkmaptypesatellite: Satellite Cloud

Mkmaptypehybrid: General maps are covered by satellite imagery

Mkmapview's agent

Mkmapview can set up a proxy object to listen to the map's related behavior

The common proxy methods are

-(void) Mapview: (Mkmapview *) Mapview didupdateuserlocation: (mkuserlocation *) userlocation;

Very frequent calls, constantly monitoring the user's current location

Each invocation, the user's latest position (userlocation parameter) is passed in.

-(void) Mapview: (Mkmapview *) Mapview regionwillchangeanimated: (BOOL) animated;

Called when the map's display area is about to change

-(void) Mapview: (Mkmapview *) Mapview regiondidchangeanimated: (BOOL) animated;

Called when the display area of the map has changed

Mkuserlocation

Mkuserlocation is actually a PIN model that includes the following properties

@property (nonatomic, copy) NSString *title;

Title displayed on the Pin

@property (nonatomic, copy) NSString *subtitle;

Sub-headings displayed on a PIN

@property (readonly, nonatomic) cllocation *location;

Location information

Set the display of the map

You can set the location and area of the map display by Mkmapview the following methods

Set the center point location of the map

@property (nonatomic) cllocationcoordinate2d centercoordinate;

-(void) Setcentercoordinate: (cllocationcoordinate2d) Coordinate animated: (BOOL) animated;

Set the display area of a map

@property (nonatomic) Mkcoordinateregion region;

-(void) Setregion: (mkcoordinateregion) region animated: (BOOL) animated;

Mkcoordinateregion

Mkcoordinateregion is a structure used to represent a region, defined as

typedef struct {

Cllocationcoordinate2d Center; The center point location of the area

Mkcoordinatespan span; span of Area

} mkcoordinateregion;

Definition of Mkcoordinatespan

typedef struct {

Cllocationdegrees Latitudedelta; Latitude span

Cllocationdegrees Longitudedelta; Longitude span

} Mkcoordinatespan;

Basic operation of a PIN

Add a PIN

-(void) Addannotation: (id <MKAnnotation>) annotation;

Add Multiple Pins

-(void) Addannotations: (Nsarray *) annotations;

Remove a PIN

-(void) Removeannotation: (id <MKAnnotation>) annotation;

Remove multiple Pins

-(void) Removeannotations: (Nsarray *) annotations;

(ID <MKAnnotation>) What is the annotation parameter?

Pin Model object: Data used to encapsulate a pin, such as the position of a pin, title, sub-title, etc.

Pin model

Create a new PIN model class

#import <MapKit/MapKit.h>

@interface Customannotation:nsobject <MKAnnotation>

/** Coordinate position */

@property (nonatomic, assign) cllocationcoordinate2d coordinate;

/** Title */

@property (nonatomic, copy) NSString *title;

/** Sub-title */

@property (nonatomic, copy) NSString *subtitle;

Map Little Notes

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.