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.