osm_flutter
osm_flutter copied to clipboard
drawRoadManually doesn't seem to work
Please see example code below. When I use drawRoad() the road is drawn, however the problem is that it tries to find the path by calling Openstreetmap's API. I don't want to use the API, I just want to connect the dots and draw lines.
I have tried using drawRoadManually but it doesn't do anything. As you can see on this screenshot, no roads are drawn:

When using drawRoad on the same geopoints, I get this:

POC to reproduce:
import 'package:flutter/material.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';
class ShowRouteScreen extends StatelessWidget {
late final MapController _mapController;
ShowRouteScreen({Key? key}) : super(key: key) {
_mapController = MapController(
areaLimit: BoundingBox(west: 15.477983, north: 48.742105, east: 23.441823, south: 45.394864)
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Test"),
),
body: OSMFlutter(
controller: _mapController,
trackMyPosition: false,
initZoom: 17,
minZoomLevel: 10,
maxZoomLevel: 19,
stepZoom: 1.0,
onMapIsReady: mapIsReady,
)
);
}
@override
Future<void> mapIsReady(bool isReady) async {
List<GeoPoint> road = [
GeoPoint(latitude: 46.41389666666667, longitude: 20.345705),
GeoPoint(latitude: 46.412905, longitude: 20.346606666666666),
GeoPoint(latitude: 46.41366, longitude: 20.34851666666667),
GeoPoint(latitude: 46.41432499999999, longitude: 20.35004),
GeoPoint(latitude: 46.413675, longitude: 20.350489999999997),
GeoPoint(latitude: 46.41321666666666, longitude: 20.349396666666667),
GeoPoint(latitude: 46.41244666666667, longitude: 20.34956833333333)
];
await _mapController.drawRoadManually(road, Colors.red, 15);
/* // example with drawRoad
var start = road.first;
var end = road.last;
road.removeLast();
road.removeAt(0);
await _mapController.drawRoad(
start,
end,
intersectPoint: road,
roadType: RoadType.foot,
roadOption: RoadOption(roadColor: Colors.red, roadWidth: 15));
*/
}
}
i will check that
the method drawRoadManually built to replace drawRoad that use osm routing api, so you can use it if you have an external routing api
theoretically you cannot build road with only 5 geo point
Thanks. Could you please add a method drawLine which would draw a line between two points?
i will add that but in 0.29+
Isn't the problem in ExtGeoPoint.toListNum ?
It is simply exchanging latitude to longitude, usually latitude is the first...
extension ExtGeoPoint on GeoPoint {
List<num> toListNum() {
return [
this.longitude,
this.latitude,
];
}
}
i will check it but usually like i told the purpose of drawRoadManually if you have your own routing service or any other third party that do the same as osrm api
Yeah, unfortunately osrm can't do horses and kayaking :D But Thanks anyway
i will add that but in 0.29+
Downloaded 0.4 today and it seems drawLine is missing... is it actually implemented and just private in some way?
can you show me the full error message
@liodali I'm replying that you said drawLine would exist in 0.29 but I don't see it in 0.4.

yeah i didnt yet impl that because i need t re-aline the web impl with android and ios and then will start refactoring draw road sorry for this lazyness from my side but i will make sure to make web impl stable soon
this is for Android.