Developers can use the interface provided by the SDK, using Baidu to provide you with the basic map data. At present, Baidu Map SDK provides a map level of 3-21, the information contained in buildings, roads, rivers, schools, parks and other content.
From V3.7.0 onwards, the map supports zooming to level 21, does not support satellite maps, heat maps, traffic layer level 21 display, open the above types of layers, the map will automatically zoom to level 20.
All overlays or overlays to the contents of the map, we collectively refer to the map overlay. such as callouts, vector graphic elements (including: polylines, polygons, circles, etc.), positioning icons, and so on. Overlays have their own geographic coordinates, and when you drag or zoom the map, they move accordingly.
Baidu Map SDK for the vast number of developers to provide the basic map and the above a variety of covering elements, with a certain level of the capping relationship, specific as follows (from the next order):
1, base basemap (including Basemap, Basemap Road, satellite map, etc.);
2, Tile layer (tileoverlay);
3, topographic map layer (groundoverlay);
4, Thermal graph layer (HEATMAP);
5. Real-time traffic diagram layer (baidumap.settrafficenabled (true););
6, Baidu City Thermal map (baidumap.setbaiduheatmapenabled (true););
7. The Basemap callout (refers to those poi elements on the basemap above);
8, Geometry layer (point, polyline, arc, Circle, Polygon);
9, callout layer (Marker), text drawing layer (text);
10, Compass layer (local map rotation and perspective changes, the default appears in the upper left corner of the compass);
11. Positioning layer (baidumap.setmylocationenabled (true););
12. Popup window layer (Infowindow);
13. Custom View (Mapview.addview (view););
Map Type
Baidu Maps Android SDK provides you with 3 types of map resources (normal vector maps, satellite maps, and blank maps), and developers can use the Maptype () method in Baidumap to set the map type. The core code is as follows:
Mmapview = (Mapview) Findviewbyid (R.id.bmapview); Mbaidumap = Mmapview.getmap (); General map Mbaidumap.setmaptype (baidumap.map_type_normal); Satellite map Mbaidumap.setmaptype (baidumap.map_type_satellite); Blank maps, base map tiles will not be rendered. Set to none in the map type, the underlying map tile layer will not be downloaded using traffic. Usage scenarios: Use with tile layers to save traffic and increase your custom tile download speed. Mbaidumap.setmaptype (Baidumap.map_type_none);
Real-time traffic map
At present, the nationwide support of multiple cities in real-time road traffic inquiries, and will be opened in other cities.
The core code for opening real-time traffic on the map is as follows:
Mmapview = (Mapview) Findviewbyid (R.id.bmapview); Mbaidumap = Mmapview.getmap (); Turn on traffic map mbaidumap.settrafficenabled (true);
Baidu City Thermal Map
Baidu Map SDK for the vast number of developers to open the heat of the local mapping ability, and then further open the Baidu's own data of the city heat map layer, to help developers to build more diverse forms of mobile applications.
The nature and use of Baidu's urban heat map similar to the real-time traffic map, just need to simple interface call, you can display the rich style of Baidu city maps.
On the map to open the Baidu City thermal force diagram of the core code as follows:
Mmapview = (Mapview) Findviewbyid (R.id.bmapview); Mbaidumap = Mmapview.getmap (); Turn on traffic map mbaidumap.setbaiduheatmapenabled (true);
map control and gesturesMap Control
Map logo
- The default is shown in the lower left corner and cannot be removed.
Using the Mmapview.setlogoposition (Logoposition.logopostionleftbottom) method, use the enumeration type to control where the display is displayed, with a total of 6 display positions (lower left, lower, lower right, top left, Upper, upper right).
- Map logo does not allow occlusion, can be through mbaidumap.setpadding (Paddingleft, Paddingtop, Paddingright, Paddingbottom); methods you can set the map boundary area to avoid UI occlusion.
Where the parameters paddingleft, Paddingtop, paddingright, and paddingbottom parameters represent the distance from the left, top, right, and bottom margins of the screen border, the pixel density in screen coordinates.
Compass
The compass is turned on by default and can be turned off.
Scale
The scale bar is turned on by default and can be turned off. Both Maxzoomlevel and Minzoomlevel are supported, and the distance represented by the scale bar at the current map level can be obtained by Mmapview.getmaplevel.
map Gestures
Map panning
Controls whether panning is enabled or disabled, which is turned on by default. If enabled, the user can pan the map
Map Zoom
Controls whether the zoom gesture is enabled or disabled, which is turned on by default. If enabled, users can tap or zoom the map view with two fingers.
Map view (3D)
Controls whether the Overlook (3D) feature is enabled or disabled, which is turned on by default. If enabled, the user can swipe down or up to the top view using double-pointing.
Map rotation
Controls whether the Map rotation feature is enabled or disabled, which is turned on by default. If enabled, the user can rotate the map using two-finger rotation.
Disable all gestures
Controls whether all gestures are suppressed together and is turned off by default. If enabled, all gestures will be disabled.
Labeling CoveringsMap Callout
Based on their actual business needs, developers can use label overlays to add callout information to the location specified in the map. The implementation method is as follows:
//define maker coordinate pointsLATLNG Point= NewLatlng(39.963175,116.400244); //Build marker iconBitmapdescriptor bitmap=Bitmapdescriptorfactory.Fromresource(R.drawable.Icon_marka); //build markeroption for adding marker on the mapOverlayoptions option= NewMarkeroptions().position(Point).icon(Bitmap); //Add marker on the map and showMbaidumap.Addoverlay(Option);
For labels that have already been added to the map, you can drag and drop gestures in the following ways:
The first step is to set the drag:
Overlayoptions Options= NewMarkeroptions().position(LlA) //Set the location of the marker.icon(adb) //Set marker icon.ZIndex(9) //Set marker level.draggable(true); //Set gesture drag//Add marker to the mapMarker= (Marker) (Mbaidumap.Addoverlay(Options));
The second step is to set the listening method:
Call the Setonmarkerdraglistener method of the Baidumap object to set the marker drag-and-drop listener mbaidumap.setonmarkerdraglistener (new Onmarkerdraglistener () {public void Onmarkerdrag (Marker Marker) { //drag in } public void Onmarkerdragend (Marker Marker) { //Drag end } public void Onmarkerdragstart (Marker Marker) { //start dragging }});
Since the v3.3.0 version, the SDK has provided
Marker Adding animationsThe ability to implement the method as follows:
Set up a set of pictures through the icons of marker, and refresh the picture resource by period setting how many frames arraylist<bitmapdescriptor> giflist = new arraylist< Bitmapdescriptor> (); Giflist.add (BdA); Giflist.add (BdB); Giflist.add (BdC); overlayoptions OoD = new Markeroptions () . Position (PT). Icons (giflist). ZIndex (0). Period, Mmarkerd = (Marker) (Mbaidumap.addoverlay (OoD)); For label overlays that have been added to the map , the following methods can be used to modify and delete operations: Marker.remove (); The Remove method that invokes the marker object implements the removal of the specified marker from the v3.6.0 version, and the SDK provides the ability to add animations to the load marker, which contains two modes of loading animation: growing from the ground and falling from the sky. Take the growth animation as an example, the specific implementation method is as follows: markeroptions OoD = new markeroptions (). Position (LlD). Icons (giflist). ZIndex (0). Period (10) ; if (animationbox.ischecked ()) {//Growth animation Ood.animatetype (Markeranimatetype.grow);} Marker mmarkerd = (Marker) (Mbaidumap.addoverlay (OoD)); Since the v3.6.0 version, the SDK provides a way to set the transparency of Marker, as follows: markeroptions OoA = New Markeroptions (). Position (LlD). Icons (giflist). ZIndex (0). period (+). Alpha (0.5); Mbaidumap.addoverlay (OoA) The specific source code should be viewed in Overlaydemo.
Point aggregation function
Since the v3.6.0 version, the new point aggregation function, you can reduce the map level, the definition of multiple points within the scope of the aggregation display as a callout point, and in the Markerclusterdemo open source, convenient for developers to modify their own.
Initialize point aggregation management class Clustermanager Mclustermanager = new Clustermanager<> (this, mbaidumap);//Add marker instance to the Point aggregation management class LATLNG LlA = new Latlng (39.963175, 116.400244); list<myitem> items = new arraylist<> (); Items.Add (New myitem (LlA)); Mclustermanager.additems (items);
Specific source code please check in the Markerclusterdemo.
Basemap Callout
Since the v3.6.0 version, the SDK has provided a Showmappoi method for controlling Basemap callouts in Baidumap, which displays Basemap callouts by default. Use this property to get a map that shows only corridor information, as follows:
Set the Basemap callout to hidden, as follows: Mbaidumap.showmappoi (FALSE)
After running, the Basemap callout is hidden and the effect
Geometry Overlay
The Map SDK offers a variety of combinations of graphic overlays that can be used to help you build more colorful map applications. Currently available geometries are: dots (dot), polyline (Polyline), Arc (ARC), Circle (Circle), Polygon (Polygon).
Here's a polygon example to show you how to use a geometry overlay:
Defines the five vertices of a polygon latlng pt1 = new Latlng (39.93923, 116.357428); LATLNG pt2 = new Latlng (39.91923, 116.327428); LATLNG PT3 = new Latlng (39.89923, 116.347428); LATLNG Pt4 = new Latlng (39.89923, 116.367428); LATLNG pt5 = new Latlng (39.91923, 116.387428); list<latlng> pts = new arraylist<latlng> (); Pts.add (PT1); Pts.add (PT2); Pts.add (PT3); Pts.add (PT4); Pts.add (PT5); Constructs the user-drawn Polygon option Object overlayoptions polygonoption = new Polygonoptions () . Points (pts) . Stroke (New Stroke (5, 0xaa00ff00)) . FillColor (0xaaffff00); Add polygon option to the map to display mbaidumap.addoverlay (polygonoption);
The results of the operation are as follows:
Android Map SDK Since the v3.5.0 version, the new polyline multi-segment color rendering capabilities, the core code to implement the following:
Construct texture resource Bitmapdescriptor custom1 = Bitmapdescriptorfactory.fromresource (R.drawable.icon_road_red_arrow); Bitmapdescriptor custom2 = Bitmapdescriptorfactory.fromresource (R.drawable.icon_road_green_arrow); Bitmapdescriptor custom3 = Bitmapdescriptorfactory.fromresource (R.drawable.icon_road_blue_arrow);//define point latlng pt1 = NEWLATLNG (39.93923, 116.357428); LATLNG pt2 = newlatlng (39.91923, 116.327428); LATLNG PT3 = newlatlng (39.89923, 116.347428); LATLNG Pt4 = newlatlng (39.89923, 116.367428); LATLNG pt5 = newlatlng (39.91923, 116.387428); Construct Texture Queue list<bitmapdescriptor>customlist = newarraylist<bitmapdescriptor> (); Customlist.add (CUSTOM1); Customlist.add (CUSTOM2); Customlist.add (CUSTOM3); List<latlng> points = newarraylist<latlng> (); List<integer> index = newarraylist<integer> ();p oints.add (PT1);//point element Index.add (0);//Set Texture index for this point Points.Add (pt2);//dot element index.add (0);//Set the texture index of the point Points.Add (PT3);//Point element Index.add (1);//Set the texture index of the point Points.Add (PT4);//Point element Index.add (2);//Set the texture index for the point Points.Add (PT5);//point element//Construct Object overlayoptionsoopolyline = Newpolylineoptions (). Width ((). Color (0xaaff0000). Points (points). Customtexturelist (customlist). Textureindex (index);//Add to map Mbaidumap.addoverlay (oopolyline);
As follows:
Since the v3.6.0 version, expanded polyline multi-segment color rendering ability: to support segmented texture rendering, segmented color rendering, the implementation of the core code is as follows:
Constructs the Polylineoptions object, adds the polyline segment color to draw the overlay, the core code is as follows:
Constructs polyline point coordinates list<latlng> points = new arraylist<latlng> ();p Oints.add (New latlng (39.965,116.404)); Points.Add (New latlng (39.925,116.454));p Oints.add (New latlng (39.955,116.494));p Oints.add (New LATLNG ( 39.905,116.554));p Oints.add (New latlng (39.965,116.604)); Build a segmented color index array list<integer> colors = new arraylist<> (); Colors.add (Integer.valueof (Color.Blue)); Colors.add (integer.valueof (color.red)); Colors.add (Integer.valueof (Color.yellow)); Colors.add (Integer.valueOf ( Color.green)); Overlayoptions oopolyline = new Polylineoptions (). Width ( . colorsvalues (colors). points (points); Added in the map Polyline mpolyline = (Polyline) mbaidumap.addoverlay (oopolyline);
Search Result Overlays
For the Retrieval function module (POI search, line planning, etc.), the Map SDK also provides the corresponding covering to quickly display the result information. These methods are open source, developers can according to their own actual request to do personalized customization.
Use the results overlay to show poi search results in the following ways:
The first step is to construct a custom poioverlay class;
Private class Mypoioverlay extends Poioverlay {public mypoioverlay (Baidumap baidumap) { super (BAIDUMAP); } @Override Public boolean onpoiclick (int index) { Super.onpoiclick (index); return true; } }
The second step is to add a custom poioverlay to the POI retrieval callback interface;
public void Ongetpoiresult (Poiresult result) { if (result = = NULL | | result.error = = SearchResult.ERRORNO.RESULT_NOT_ FOUND) { return; } if (Result.error = = SearchResult.ERRORNO.NO_ERROR) { mbaidumap.clear (); Create Poioverlay Poioverlay overlay = new Mypoioverlay (mbaidumap); Set overlay to handle callout Click event mbaidumap.setonmarkerclicklistener (overlay); Set Poioverlay data overlay.setdata (result); Add Poioverlay to map overlay.addtomap (); Overlay.zoomtospan (); return; } }
The results of the operation are as follows:
Show bus transfer results with Transitrouteoverlay:
Add Transitrouteoverlay in bus route planning callback method to show transfer information public void Ongettransitrouteresult (transitrouteresult result) { if (result = = NULL | | Result.error! = SearchResult.ERRORNO.NO_ERROR) { //No results found return; } if (Result.error = = SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) { //from or through point addresses are ambiguous, get suggested query information via the following interface // Result.getsuggestaddrinfo () return; } if (Result.error = = SearchResult.ERRORNO.NO_ERROR) { route = Result.getroutelines (). get (0); Create a bus route plan line overlay transitrouteoverlay overlay = new Mytransitrouteoverlay (mbaidumap); Set up bus route planning data Overlay.setdata (route); Add the bus route planning overlay to the map Overlay.addtomap (); Overlay.zoomtospan (); } }
The results of the operation are as follows:
android--Base map of Baidu Map (c)