Because of system reasons, iOS does not allow the use of third-party positioning, so the Map SDK positioning method, in essence, the native location of the two encapsulation. Through encapsulation, developers can be more convenient to use. In addition, the Map SDK also provides the appropriate positioning layer (supporting the positioning of the three-state effect) to help developers display the current location information.
Note: Since the iOS8, the system positioning function has been upgraded, the SDK in order to achieve the latest adaptation, Since the v2.5.0 has also made the corresponding changes, developers in the use of positioning function before the need to add in Info.plist (the following two selected, two are added by default to use Nslocationwheninuseusagedescription):
Nslocationwheninuseusagedescription, allows you to obtain a GPS description when using the foreground
Nslocationalwaysusagedescription, allow permanent use of GPS description
The positioning function can be separated from the map function, and the individual positioning function is used as follows:
First, add the SDK to the project ...
Add header file #import <BaiduMapAPI_Location/BMKLocationService.h>
Add Agent Bmklocationservicedelegate
-(void) viewdidload
{
Initialize Bmklocationservice
_locservice = [[Bmklocationservice alloc]init];
_locservice.delegate = self;
Start Locationservice
[_locservice Startuserlocationservice];
}
Implement related delegate processing location information update
Process position coordinates update (second update, if only need to obtain once, after positioning success stop positioning or set delegate to nil)
Stop positioning commands as follows ([Self.locservice Stopuserlocationservice];)
-(void) Didupdatebmkuserlocation: (bmkuserlocation *) userlocation
{
NSLog (@ "didupdateuserlocation lat%f,long%f", UserLocation.location.coordinate.latitude, UserLocation.location.coordinate.longitude);
}
If you only need to get the current latitude and longitude, then the following 2 commands can be ignored
Processing direction Change information
-(void) didupdateuserheading: (bmkuserlocation *) userlocation
{
NSLog (@ "Heading is%@", userlocation.heading);
}
The function of displaying positioning information is located in the function module of "Map and overlay", the choice should be paid attention to when using. The core code is as follows:
The following _mapview are Bmkmapview objects
_mapview.showsuserlocation = yes;//display positioning layer
[_mapview updatelocationdata:userlocation];