IOS Baidu positioning (get latitude and longitude)

Source: Internet
Author: User
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];

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.