1, Foreword
Path planning is generally based on the longitude and latitude of the starting point coordinates and the longitude and latitude of the ending point coordinates to find out the appropriate route. As for the start coordinates and end coordinates, the first thing to do is to directly input the specific Chinese address. Later, baidu map does not open this function, which seems to become a charging function, but the function of mutual conversion of longitude and latitude and address is still open, so there is one more step. Later, it is to directly input the longitude and latitude coordinates for query, which needs to be input manually, What we do now is to directly select points on the map. Select the radio box behind the starting coordinates, and then directly select points on the map. The corresponding longitude and latitude coordinate values will be filled in automatically, which is relatively more humanized.
When you get the track point coordinate set to draw, you actually call the addPolyline function to draw. Note that the received track point coordinate set is likely to be multi-section rather than a complete section. What is transmitted is an array of arrays, so you need to make a cycle to draw the received track point set by segments. As for the line color + border + transparency, you can set it, In order to distinguish the original path query from the automatically drawn path.
In fact, another very useful function can be derived from this function, which is to take out the track point coordinate set of the queried path for other processing, such as sending it to the equipment (aircraft, robot, etc.) to make the equipment move according to this track point. In order to ensure that the obtained track point coordinate set is correct, You can also redraw the track points with different colors and compare them with the track lines obtained by querying the route. If the height coincides, it indicates that it is correct.
2, Functional features
- Both online map and offline map modes are supported.
- It also supports webkit kernel, webengine kernel, minilink kernel and IE kernel.
- Support setting multiple annotation points, including name, address, longitude and latitude.
- You can set whether the map can be clicked, dragged and zoomed with the mouse wheel.
- You can set the protocol version, secret key, theme style, central coordinate, central city, geocoding location, etc.
- You can set the zoom scale and level of the map, and the visibility of thumbnails, scale bars, road information and other controls.
- Support map interaction, such as mouse click to obtain the longitude and latitude of the corresponding position.
- It supports route query, and can set the starting point location, terminal location, route mode, route mode and route scheme (minimum time, minimum transfer, minimum walking, no subway, minimum distance and avoiding Expressway).
- It can display point, line and surface tools, and can directly draw lines, points, rectangles, circles, etc. on the map.
- You can set the administrative division, specify the drawing layer of a certain urban area, and automatically output the boundary points of the administrative division to the js file for the offline map.
- Multiple covers can be added statically or dynamically. Support point, polyline, polygon, rectangle, circle, arc, point aggregation, etc.
- Function interface is provided to process longitude and latitude resolution into address and address resolution into longitude and latitude coordinates.
- The provided demo can directly select points to perform corresponding processing, such as route query.
- You can get the point coordinate information set queried by the route, such as for robot coordinate navigation.
- It encapsulates rich functions, such as deleting specified points and all points, deleting specified covers and all covers, etc.
- The label point pop-up box information can be customized in standard html format.
- Mark point click event optional 0 - do not process 1 - pop up box 2 - send signal.
- Annotation points can be animated 0 - do not handle 1 - jump 2 - fall
- Label points can be set to local picture files, etc.
- The function interface is friendly and unified, simple and convenient to use, just one class.
- Support js dynamic interactive adding points, deleting points, clearing points and resetting points without refreshing the page.
- Support any Qt version, any system and any compiler.
3, Experience address
- Experience address: https://pan.baidu.com/s/1ZxG-oyUKe286LPMPxOrO2A Extraction code: o05q file name: bin_map.zip
- Domestic sites: https://gitee.com/feiyangqingyun
- International sites: https://github.com/feiyangqingyun
- Personal homepage: https://blog.csdn.net/feiyangqingyun
- Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/
4, Renderings
5, Related code
void MapBaiDu::addRoute(QStringList &list) { if (startAddr.isEmpty() || endAddr.isEmpty()) { return; } //The address is marked with, indicating the longitude and latitude form adopted if (startAddr.contains(",")) { list << QString(" var p1 = getPoint('%1');").arg(startAddr); list << QString(" var p2 = getPoint('%1');").arg(endAddr); } else { list << QString(" var p1 = \"%1\";").arg(startAddr); list << QString(" var p2 = \"%1\";").arg(endAddr); } //0 - bus 1 - driving 2 - walking 3 - cycling QString renderOptions = QString("{renderOptions:{map:map, panel:\"result\"}, policy:%1}").arg(policyType); if (routeType == 0) { list << QString(" var route = new %1.TransitRoute(map, %2);").arg(mapFlag).arg(renderOptions); } else if (routeType == 1) { list << QString(" var route = new %1.DrivingRoute(map, %2);").arg(mapFlag).arg(renderOptions); } else if (routeType == 2) { list << QString(" var route = new %1.WalkingRoute(map, %2);").arg(mapFlag).arg(renderOptions); } else if (routeType == 3) { list << QString(" var route = new %1.RidingRoute(map, %2);").arg(mapFlag).arg(renderOptions); } //Gets the series of points of the path QStringList temp; temp << QString(" route.setSearchCompleteCallback(function(results) {"); temp << QString(" if (route.getStatus() != BMAP_STATUS_SUCCESS) {"); temp << QString(" return;"); temp << QString(" }"); //There may be multiple routes to obtain the route results. It is generally optimal to take the first route by default temp << QString(" var plan = results.getPlan(0);"); //Get total time temp << QString(" var duration = plan.getDuration(true);"); //Get total distance temp << QString(" var distance = plan.getDistance(true);"); //Get the number of line segments, there may be multiple segments temp << QString(" var count = plan.getNumRoutes(0);"); //temp << QString(" alert(count + '|' + duration + '|' + distance);"); //Gets an array of all coordinate points temp << QString(" var pointsAll = [];"); temp << QString(" for (var i = 0; i < count; ++i) {"); temp << QString(" var pts = plan.getRoute(i).getPath();"); temp << QString(" var points = [];"); temp << QString(" for (var j = 0; j < pts.length; ++j) {"); temp << QString(" var point = pts[j].lng + ',' + pts[j].lat;"); temp << QString(" points.push(point);"); temp << QString(" }"); temp << QString(" pointsAll.push(points.join(';'));"); temp << QString(" }"); //Return total mileage and total time result temp << QString(" receiveData('routeresult', duration + '|' + distance);"); //Returns a set of coordinate points separated by | temp << QString(" receiveData('routepoints', pointsAll.join('|'));"); temp << QString(" })"); list << temp.join("\r\n"); //Query path list << QString(" route.search(p1, p2);"); }