iOS Location Services and map development (1)---get latitude and longitude

Source: Internet
Author: User

Location services are located by GPs and other means to locate their own location, and then through the map labeled.

Location services and map development in iOS were done using two sets of APIs.

1. Location Services:

The iOS system offers 3 different targeting pathways:

1>wifi: By querying the location of a WiFi router, iPhone, IPod Touch, ipad can be used.

2> Cellular mobile Phone base station positioning: Mobile operator Base station positioning

3>gps satellite positioning: Through the three-star GPS satellite location positioning, the most accurate, but large power consumption

iOS does not, like the Android system, specify which route to use for location services programming. The iOS API masks the underlying details, and developers and users don't know which way the device is positioned, and the iOS system uses the best solution based on the device and its surroundings. Specifically: If you can GPS information, then the device priority to use GPS positioning, or use WiFi or cellular base station positioning, WiFi and cellular base station priority to use WiFi, if unable to connect to WiFi use cellular base station location.

1.1. Location Service Programming

After iOS 6, location services primarily use the Corelocaation framework, which uses Cllocationmanager, Cllocationmanagerdelegate, and cclocation primarily when locating.

Cllocationmanager class: The Location service Management class, which enables us to obtain the location information of the device and the height of information , but also to monitor the device into an area, but also to help us get the direction of the device.

Cllocationmanagerdelegate class: Is a delegate agreement for the Cllocationmanager class.

Cllocation class: Encapsulates location and height information.

The following specific actions:

The first step, create a new Singleview blank project

Step two: Introducing the framework into the project:corelocation.framework

in the main interface of the controller ViewController.h file, we do nothing,. m file, we need to declare a Cllocationmanager* Locationmanager's properties, We let it implement the cllocationmanagerdelegate protocol, and implement the Proxy method Didupdatelocations and Didfailwitherror, as follows:/ /// VIEWCONTROLLER.M

//Cllocationmanager////Created by Apple on 14-5-11.//Copyright (c) 2014 Super. All rights reserved.//#import "ViewController.h"#import<CoreLocation/CoreLocation.h>@interfaceViewcontroller () <CLLocationManagerDelegate>{} @property (Nonatomic,strong) Cllocationmanager*Locationmanager;@end@implementationViewcontroller
- (void) viewdidload{[Super Viewdidload]; //Additional setup after loading the view, typically from a nib.
Location Services Management Object initialization
  Self.locationmanager = [[Cllocationmanager alloc] init]; //DelegateSelf.locationmanager.Delegate=Self ; //The desired location accuracy.Self.locationManager.desiredAccuracy =kcllocationaccuracybest; //Specifies the minimum update distance in meters.Self.locationManager.distanceFilter=Kcldistancefilternone; Self.locationManager.purpose=@"To provide functionality based on user 's current location.";}-(void) Viewwillappear: (BOOL) animated
{
[Super viewwillappear:animatted];
Start positioning
 [Self.locationmanager startupdatinglocation];
}

-(void) Viewwilldisappear: (BOOL) animated
{
[Super viewwilldisappear:animated];
Stop positioning
  
[Self.locationmanager stopupdatinglocation];
}@end
#pragmaThe mark-delegate method is used to implement the update of the location-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{//the current location of the deviceCllocation *currlocation =[Locations Lastobject]; NSString*latitude = [NSString stringWithFormat:@"Latitude:%3.5f", CurrLocation.coordinate.latitude]; NSString*longitude = [NSString stringWithFormat:@"Longitude:%3.5f", CurrLocation.coordinate.longitude]; NSString*altitude = [NSString stringWithFormat:@"Height Value:%3.5f", Currlocation.altitude];}- (void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (Nserror *) error{NSLog (@"Error:%@", error.localizeddescription);}

LocationManager:didUpdateLocations:iOS 6 new method for locating a successful call to replace the previous locationManager:didUpdateToLocation:fromLocation: method.

Locationmanager:didfailwitherror: Failed to locate.

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.