https://github.com/brasilflutter/flutter_geo_direction
A package to find routes between geolocation points.
https://github.com/brasilflutter/flutter_geo_direction
Last synced: 6 days ago
JSON representation
A package to find routes between geolocation points.
- Host: GitHub
- URL: https://github.com/brasilflutter/flutter_geo_direction
- Owner: brasilflutter
- License: mit
- Created: 2023-04-21T19:01:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T02:35:58.000Z (about 2 years ago)
- Last Synced: 2026-01-11T10:15:52.862Z (6 months ago)
- Language: Dart
- Homepage: https://pub.dev/packages/geo_direction
- Size: 5.14 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# GeoDirection
Um pacote Flutter que usa a API do Google Maps para obter rotas entre coordenadas geográficas. Ele retorna uma lista de pontos LatLng que pode ser usada para renderizar uma rota no Google Maps.
## Instalação
Adicione esta linha ao pubspec.yaml do seu projeto:
```
dependencies:
geo_direction:
```
E rode o seguinte comando:
```
flutter pub get
```
## Screenshots

## Exemplo usando em conjunto com o google_maps_flutter
```dart
class HomeView extends StatefulWidget {
const HomeView({super.key});
@override
State createState() => _HomeViewState();
}
class _HomeViewState extends State {
final Completer _controller = Completer();
static const LatLng sourceLocation = LatLng(37.33500926, -122.03272188);
static const LatLng destination = LatLng(37.33429383, -122.06600055);
@override
void initState() {
super.initState();
getPolyPoints();
}
List polylineCoordinates = [];
void getPolyPoints() async {
final geoDirection = GeoDirection();
final result = await geoDirection.getDirectionsBetweenCoordinates(
request: GeoRequestDto(
googleApiKey: "YOUR_API_KEY",
origin: PointLatLngDto(
latitude: sourceLocation.latitude,
longitude: sourceLocation.longitude,
),
destination: PointLatLngDto(
latitude: destination.latitude,
longitude: destination.longitude,
),
),
);
if (result.points.isNotEmpty) {
for (var point in result.points) {
polylineCoordinates.add(
LatLng(point.latitude, point.longitude),
);
}
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: GoogleMap(
mapType: MapType.hybrid,
initialCameraPosition: const CameraPosition(
target: sourceLocation,
zoom: 13.5,
),
markers: {
const Marker(
markerId: MarkerId("source"),
position: sourceLocation,
),
const Marker(
markerId: MarkerId("destination"),
position: destination,
),
},
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
polylines: {
Polyline(
polylineId: const PolylineId("route"),
points: polylineCoordinates,
color: const Color(0xFF7B61FF),
width: 6,
),
},
),
);
}
}
```
## Autores
- [@viniciusoliverrs](https://github.com/viniciusoliverrs)