Use of IOS Baidu map API-positioning function

Source: Internet
Author: User

Recently, my boss had to set up Baidu maps, so he couldn't find some materials to ponder over. To use the Baidu map API, go to the Baidu official website to download the API and apply for the key (just follow the instructions on the Baidu official website ).

After applying for the key, download the Baidu demo, change the key in it to the one you just applied for, and run it. (Note: if there are many compilation errors when writing your own program, first check whether all the required frameworks have been added, and then select project> Target>
Build settings-> linking-> Other linker flags add-all_load)

Location mainly uses the function (void) mapview (bmkmapview *) mapview didupdatelocation (bmkuserlocation *) userlocation entrusted by bmkmapview. This function can be used to obtain the current longitude and latitude of the user.

It is possible that the longitude and latitude cannot meet the requirements of everyone. Instead, we hope to directly see the place name of our website. This requires the bmkserarc delegate class bmksearchdelegate. First, call the reversegeocode function of bmkserach, and then in the-(void) of bmksearchdelegate)
Onget

Addrresult: (bmkaddrinfo *) Result errorcode: (INT) error function to obtain the result.

Below are some key codes:

-(Void) mapview :( bmkmapview *) mapview didupdateuserlocation :( bmkuserlocation *) userlocation

{

Locallatitude = userlocation. Coordinate. Latitude; // Save the obtained longitude and latitude.

Locallongpolling = userlocation. Coordinate. longpolling;


If (userlocation! = Nil)

{

Nslog (@ "% F", userlocation. Location. Coordinate. Latitude, userlocation. Location. Coordinate. longpolling );

}

[_ Mapview setcentercoordinate: userlocation. Coordinate animated: Yes]; // move the map to the location

Bool flag = [_ search reversegeocode: pt]; // The Anti-geocode automatically calls the following delegate function to obtain the result.

If (! Flag ){

Nslog (@ "search failed! ");

}

}

-(Void) ongetaddrresult :( bmkaddrinfo *) Result errorcode :( INT) Error

{

Nslog (@ "% @", result. straddr );

Citystr = result. addresscomponent. streetname; // the street name.

Citystreetname = result. addresscomponent. City; // city name

Nslog (@ "% @", citystreetname );

Nslog (@ "% @", citystr );

Nslog (@ "% @", result. addresscomponent. streetnumber); // output the street number of the City

}

Baidu map is still very powerful. Now it is just a glimpse of the leopard, and the function will be added later.

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.