【问题标题】:how to draw path between two location in using map box?如何在使用地图框的两个位置之间绘制路径?
【发布时间】:2021-04-05 02:59:50
【问题描述】:

我想在两点之间绘制路径。我正在使用flutter_map 0.10.1+1 包来包含地图。

我正在使用地图框 api 在两个位置之间获取点。当我使用该点绘制折线时,它会绘制直线,而不是在道路上绘制线。

例如,当我尝试在两个位置之间获取点时,我得到以下点:

LatLng(latitude:21.202751, longitude:72.838807)
LatLng(latitude:21.198725, longitude:72.836119)
LatLng(latitude:21.196459, longitude:72.83742)
LatLng(latitude:21.195418, longitude:72.836605)
LatLng(latitude:21.195194, longitude:72.836577)
LatLng(latitude:21.189253, longitude:72.832431)
LatLng(latitude:21.186454, longitude:72.829726)

查看下图我是如何画线的。

【问题讨论】:

  • 您需要使用某种 API 来获取遵循道路的路径,这不是 2 行代码就能解决的任务。此外,该 AFAIK 没有免费的 API
  • @DimaRostopira 我没有找到任何直接的方法,所以我尝试了这种方法。你能像 googlemap 一样分享 mapbox 的任何直接方式吗?

标签: flutter mapbox flutter-dependencies


【解决方案1】:

您需要在您使用的包中指定折线模式类型。

 GoogleMapPolyline googleMapPolyline =
      new GoogleMapPolyline(apiKey: "yourkeyhere");

googleMapPolyline.getCoordinatesWithLocation(
        origin: LatLng(40.6782, -73.9442),
        destination: LatLng(40.6944, -73.9212),
         mode: RouteMode.driving);--->You need to set the mode type

【讨论】:

猜你喜欢
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-03
相关资源
最近更新 更多