Qt map compilation comprehensive application 47 - longitude and latitude address mutual conversion

Posted by cmpennington on Sat, 08 Jan 2022 04:17:36 +0100

1, Foreword

The function of exchanging address longitude and latitude is only available in online maps, because you need to go to the server to query the corresponding data and get the returned data. BMAP needs to be used in Baidu maps Geocoder realizes the exchange of these two functions. It has built-in getPoint function, which is responsible for converting the address into latitude and longitude coordinates, and getLocation function, which is responsible for converting the latitude and longitude coordinates into addresses. Therefore, these two functions are encapsulated into JS functions, which can be called directly every time.

The function of converting address and longitude and latitude is also often used. For example, the last route scheme query function. Previously, the official website provided direct input of Chinese characters of departure and destination to query the optimal route. Later, only the longitude and latitude coordinates of departure and destination can be input. This is a little around. Let users input what longitude and latitude coordinates, What the hell is that? Few users can understand it, so you need to first query the corresponding latitude and longitude coordinates of the Chinese characters of the starting point and destination entered by the user, and then input the query results into the JS function of route query. Why did you suddenly turn off the function of automatic longitude and latitude conversion of this address? I went to the backstage to have a look. It turned out that this function has become a charging module.

2, Functional features

  1. Both online map and offline map modes are supported.
  2. It also supports webkit kernel, webengine kernel, minilink kernel and IE kernel.
  3. Support setting multiple annotation points, including name, address, longitude and latitude.
  4. You can set whether the map can be clicked, dragged and zoomed with the mouse wheel.
  5. You can set the protocol version, secret key, theme style, central coordinate, central city, geocoding location, etc.
  6. You can set the zoom scale and level of the map, and the visibility of thumbnails, scale bars, road information and other controls.
  7. Support map interaction, such as mouse click to obtain the longitude and latitude of the corresponding position.
  8. 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).
  9. It can display point, line and surface tools, and can directly draw lines, points, rectangles, circles, etc. on the map.
  10. 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.
  11. Multiple covers can be added statically or dynamically. Support point, polyline, polygon, rectangle, circle, arc, point aggregation, etc.
  12. Function interface is provided to process longitude and latitude resolution into address and address resolution into longitude and latitude coordinates.
  13. The provided demo can directly select points to perform corresponding processing, such as route query.
  14. You can get the point coordinate information set queried by the route, such as for robot coordinate navigation.
  15. It encapsulates rich functions, such as deleting specified points and all points, deleting specified covers and all covers, etc.
  16. The label point pop-up box information can be customized in standard html format.
  17. Mark point click event optional 0 - do not process 1 - pop up box 2 - send signal.
  18. Annotation points can be animated 0 - do not handle 1 - jump 2 - fall
  19. Label points can be set to local picture files, etc.
  20. The function interface is friendly and unified, simple and convenient to use, just one class.
  21. Support js dynamic interactive adding points, deleting points, clearing points and resetting points without refreshing the page.
  22. Support any Qt version, any system and any compiler.

3, Experience address

  1. Experience address: https://pan.baidu.com/s/1ZxG-oyUKe286LPMPxOrO2A Extraction code: o05q file name: bin_map.zip
  2. Domestic sites: https://gitee.com/feiyangqingyun
  3. International sites: https://github.com/feiyangqingyun
  4. Personal homepage: https://blog.csdn.net/feiyangqingyun
  5. Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/

4, Renderings

5, Related code

void MapBaiDu::addGeocoder(QStringList &list)
    list << QString("  var geo = new %1.Geocoder();").arg(mapFlag);
    //Address resolved to coordinates
    list << QString("  function getPointByAddr(addr) {");
    list << QString("    geo.getPoint(addr, function(result) {");
    list << QString("      if (result) {");
    list << QString("        var point = result.lng + ',' + result.lat;");
    list << QString("        receiveData('geocoder', point);");
    list << QString("      }");
    list << QString("    });");
    list << QString("  }");
    //Resolve coordinates to addresses
    list << QString("  function getAddrByPoint(point) {");
    list << QString("    geo.getLocation(getPoint(point), function(result) {");
    list << QString("      if (result) {");
    list << QString("        receiveData('geocoder', result.address);");
    list << QString("      }");
    list << QString("    });");
    list << QString("  }");

void frmMapBaiDu::on_btnAddrToPoint_clicked()
    QString addr = ui->txtDeviceAddr->text().trimmed();

void frmMapBaiDu::on_btnPointToAddr_clicked()
    QString point = ui->txtDevicePoint->text().trimmed();