liodali / OSM-Routing-Client-Dart

flutter package for osrm client api and open source routing service
https://pub.dev/packages/routing_client_dart
MIT License
18 stars 12 forks source link

I was trying to use your api, but I've been facing several difficulties. #4

Closed AlysonTrizotto closed 2 years ago

AlysonTrizotto commented 2 years ago

Hello how are you?

I was trying to use your api, but I've been facing several difficulties.

I can't actually use it. I can't use PolyLines, nor can I use routes. Would you help me?

liodali commented 2 years ago

can you specify more details about the those details ?

AlysonTrizotto commented 2 years ago

I'm trying to take the PolyLine and implement it on the map. I've done it this way, however I noticed that the library's return is in String. Do you have any idea how I get the PolyLine and implement it on the map? Here's the code snippet I'm using.

late List<Polyline> polyLines = [];


[..]
layers: [
                  TileLayerOptions(
                      urlTemplate:
                          "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                      //   "https://api.openrouteservice.org/v2/directions/driving-car?api_key=${chave}&start=${lat_init},${lng_init}&end=${lat_final},${lng_final}",
                      subdomains: ['a', 'b', 'c']),
                  PolylineLayerOptions(
                    polylines: polyLines,
                  ),
[..]

//button
Positioned(
              bottom: 130.0,
              left: 20.0,
              child: FloatingActionButton(
                  heroTag: 'rota',
                  elevation: 50,
                  child: Text(
                    'IR',
                    style: TextStyle(fontSize: 25),
                  ),
                  onPressed: () {
                    routeHelper();
                  }),
            ),

 Future<void> routeHelper() async {
    List<LngLat> waypoints = [
      LngLat(lat: latLng.latitude, lng: latLng.longitude),
      LngLat(lat: currentCenter.latitude, lng: currentCenter.longitude),
    ];
    final manager = OSRMManager();
    final road = await manager.getTrip(
      waypoints: waypoints,
      roundTrip: true,
      destination: DestinationGeoPointOption.last,
      source: SourceGeoPointOption.first,
      geometry: Geometries.polyline,
      steps: true,
      languageCode: "en",
    );
    polyLines = Geometries.polyline as List<Polyline>;
    print('PolyLineEndoced: ' + road.details.roadLegs.toString());
  }

full code https://github.com/AlysonTrizotto/LocalizaCliente/blob/main/lib/componentes/rota.dart

AlysonTrizotto commented 2 years ago

My question is, how do I get the return of the polyline? The library generates a route, how do I get this route created?

liodali commented 2 years ago

use can use this library (https://pub.dev/packages/google_polyline_algorithm) to transform polylineEncoded to list of [[lon,lat]] that you can with that library

AlysonTrizotto commented 2 years ago

Hello. I understood. Thanks. I'm studying this library.