1) 用于添加标记:
List<Marker> markers = [];
内部构建方法:
FlutterMap(
mapController: _mapController,
options: MapOptions(
center: LatLng(41.238250, 69.342939),
zoom: 9.6,
onTap: (latlng) {
setState(() {
markers.add(
Marker(
width: 150.0,
height: 150.0,
point: latlng,
builder: (ctx) => const Icon(
Icons.location_on,
color: Colors.red,
size: 35.0,
),
),
);
});
}),
layers: [
MarkerLayerOptions(
markers: [
for (int i = 0; i < markers.length; i++) markers[i]
],
),
],
),
2) 如果您想查询两点之间的路线,您可以使用此服务,它是免费的。 http://project-osrm.org
我用来获取两点之间路线的链接。
https://api.openrouteservice.org/v2/directions/driving-car?api_key=$OSRM_API_KEY&start=${origin.longitude},${origin.latitude}&end=${destination.longitude},${destination.latitude}
需要,API Key 和起点 lat-long 和终点 lat-long。
响应为您提供多个经纬度点,如果您将这些点提供给地图的 polyLine 参数,它将在两点之间为您绘制一条道路线
如果您需要对我的回答的某些部分进行任何澄清,请告诉我