The Baidu Map API app for iOS development

Source: Internet
Author: User

At present we are doing iOS development in most of the GoogleMap map, iOS itself is also googlemap, but if we want to display in real-time traffic information and other features on the map, GoogleMap is not, so sometimes we can apply Baidu map to do the application. Let me briefly introduce the application of Bmapkit:

A: First we have a little different from the one developed with GoogleMap, you need to create a map of the Bmkmapmanager management application, and without this class, the map cannot be displayed.

The following red font is their own in the official Baidu application map Api--key;

Bmkmapmanager *_mapmanager = [[Bmkmapmanager alloc] init];

BOOL ret = [_mapmanager start: @ "c3252c69edb6d21a10b3fc9657fd1ddc7e0000**" Generaldelegate:self];

if (!ret) {

NSLog(@ "Manager start failed!" );

}

Two: Add Bmkmapview in view, set bmkmapviewdelegate, add annotation (record points of interest, bmkannotation), At the same time each POI can set its title (set annotation's title), as well as subtitle (sub-title).

@interface Mapbaidu:uiviewcontroller <bmkmapviewdelegate> {}

@property (nonatomic, strong) Bmkmapview *_mapview;

@end


-(void) Viewdidload {

_mapview = [[bmkmapviewalloc] initwithframe: CGRectMake(0, ,     (377)]; Create Mkmapview

[Self. Viewaddsubview:_mapview];

[_mapviewrelease];

_mapview. Delegate =self; Set up proxy

_mapview. showsuserlocation =YES; Set to show user location

cllocationcoordinate2d coordinate; Set latitude and longitude

Coordinate.         latitude =40.027283; Latitude

Coordinate.      longitude =116.313217; Longitude

bmkcoordinateregion viewregion =bmkcoordinateregionmake(coordinate, Bmkcoordinatespanmake(1.0 ,1.0));

bmkcoordinateregion adjustedregion = [_mapviewregionthatfits:viewregion];

[_mapviewsetregion:adjustedregion animated:YES];

}

The last line above: sets the latitude and longitude range of the current map, which may be adjusted to fit the extent of the Map window display. Region is a property of the Bmkmapview, type bmkcoordinateregion, this line means to create a coordinate-centric, up and down about 0.5 warp (latitude) degrees. But then we need to pay attention to the problem is that the area created is a square, does not conform to the Bmkmapview scale we need, and then regionthatfits to adjust the display range with the method.


Represents an area of latitude and longitude

typedef struct {

Cllocationcoordinate2d Center; < center point latitude and longitude coordinates

Bmkcoordinatespan span; < latitude and longitude range

} bmkcoordinateregion;


Represents a range of latitude and longitude

typedef struct {

cllocationdegrees Latitudedelta; ///< Latitude range

cllocationdegrees Longitudedelta; ///< Longitude range

} Bmkcoordinatespan;



Three: Let's briefly say delegate

1: Call function when map area is changed:

-(void) Mapview: (bmkmapview *) Mapview regionwillchangeanimated: (BOOL) animated;

-(void) Mapview: (bmkmapview *) Mapview regiondidchangeanimated: (BOOL) animated;

2:annotation

* generate the corresponding view according to Anntation

-(Bmkannotationview *) Mapview: (bmkmapview *) Mapview viewforannotation: (ID <bmkannotation>) annotation;

* This interface is called when Mapview new annotation views are added

-(void) Mapview: (bmkmapview *) Mapview didaddannotationviews: (nsarray *) views;

* When a annotation views is selected, this interface is called

-(void) Mapview: (bmkmapview *) Mapview Didselectannotationview: (bmkannotationview *) view;

* When a annotation views is deselected , this interface is called

-(void) Mapview: (bmkmapview *) Mapview Diddeselectannotationview: (bmkannotationview *) view;

and annotation is divided into two parts: Bmkanotation the class is the protocol of the callout point, provides the basic information function of the labeling class, title and subtitle are headings and sub-headings respectively, and can set the left side of the label. The setcoordinate will be called when towing;

Bmkannotationview Displays the view class for the callout point, which inherits UIView, can set the image of this view display, can set the Centeroffset (center position, positive offset to move the view ultra-right, negative to the upper right, in pixels), You can also set the Calloutoffset to change the fade-out bubble position (positive offset to move the view over the lower right, negative to the upper left, in pixels). You can also set its touch events, which are yes by default, can be checked, or enabled = NO. The other attributes are: Selected,canshowcallout,leftcalloutaccessoryview,rightcalloutaccessoryview. Wait a minute

Four: Call function when local map view is positioned:

* When a annotation views is deselected , this interface is called

-(void) Mapview: (bmkmapview *) Mapview Diddeselectannotationview: (bmkannotationview *) view;

* This function is called when the map view is going to start positioning

-(void) Mapviewwillstartlocatinguser: (bmkmapview *) Mapview;

* This function is called after the map view stops locating

-(void) Mapviewdidstoplocatinguser: (bmkmapview *) Mapview;

* This function is called after a failed location

-(void) Mapview: (bmkmapview *) Mapview didfailtolocateuserwitherror: (nserror *) error;

* This function is called after the user location is updated

-(void) Mapview: (bmkmapview *) Mapview didupdateuserlocation: (bmkuserlocation *) userlocation;

V: Call this interface when there is a overlay (shadow indicates an area) or is newly added

* generate the corresponding view according to overlay

-(Bmkoverlayview *) Mapview: (bmkmapview *) Mapview Viewforoverlay: (ID <bmkoverlay>) overlay;

* This interface is called when Mapview new overlay views are added

-(void) Mapview: (bmkmapview *) Mapview didaddoverlayviews: (nsarray *) overlayviews;

Six: call this interface when you click Annotation View pop-up bubble

* Call this interface when you click on Annotation View pop-up bubble

-(void) Mapview: (bmkmapview *) Mapview annotationviewforbubble: (bmkannotationview *) view;


Nine: annotation view has many different states, in different states we can set different operations, drag annotation View when the state changes

-(void) Mapview: (bmkmapview *) Mapview Annotationview: (bmkannotationview *) View didchangedragstate: ( bmkannotationviewdragstate) newstate

Fromoldstate: (bmkannotationviewdragstate) oldstate;


Enum {

Bmkannotationviewdragstatenone = 0, ///< quiescent state .

Bmkannotationviewdragstatestarting, ///< start dragging

Bmkannotationviewdragstatedragging, ///< drag in

Bmkannotationviewdragstatecanceling, ///< Cancel drag

bmkannotationviewdragstateending ///< drag end

};


typedef Nsuinteger bmkannotationviewdragstate;

Transferred from: http://blog.csdn.net/sanpintian/article/details/7402853

The Baidu Map API app for iOS development

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.