gmaps_by_road_distance_calculator
यह एक पैकेज है जो मानचित्र में एक बिंदु से दूसरे बिंदु तक रोड दूरी की गणना करता है।
यह एक फ्लटर पैकेज है जो एक स्थान से दूसरे स्थान तक मार्ग की दूरी और बहुपद रेखा के साथ प्राप्त करने के लिए है।
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
A Dart package for calculating distances along roads and routes using multiple APIs and formats.
Add the package to your pubspec.yaml:
dependencies:
gmaps_by_road_distance_calculator: ^1.0.0
Then run:
flutter pub get
import 'package:gmaps_by_road_distance_calculator/gmaps_by_road_distance_calculator.dart';
Calculate straight-line distances between geographical points:
final calculator = ByRoadDistanceCalculator();
final points = [
LatLng(37.7749, -122.4194), // San Francisco
LatLng(34.0522, -118.2437), // Los Angeles
];
// Calculate straight-line distance in kilometers
final distance = calculator.calculateDistance(points);
print('Distance: $distance km');
Calculate actual road distance between two points using the OSRM service:
final calculator = ByRoadDistanceCalculator();
final start = LatLng(37.7749, -122.4194); // San Francisco
final end = LatLng(34.0522, -118.2437); // Los Angeles
// Calculate driving distance
calculator.calculateDistanceViaOSRM(
start: start,
end: end,
mode: TravelModes.driving,
).then((result) {
print('Driving distance: ${result.distance} km');
print('Route consists of ${result.points.length} points');
});
// Calculate walking distance
calculator.calculateDistanceViaOSRM(
start: start,
end: end,
mode: TravelModes.walking,
).then((result) {
print('Walking distance: ${result.distance} km');
});
Track and update distance in real-time as new points are added:
final calculator = ByRoadDistanceCalculator();
// Listen for distance updates
calculator.distanceUpdates.listen((distance) {
print('Current distance: $distance km');
});
// Add points as they become available (e.g., from GPS)
calculator.addPoint(LatLng(37.7749, -122.4194));
calculator.addPoint(LatLng(37.7850, -122.4100));
calculator.addPoint(LatLng(37.7950, -122.4000));
// Reset tracking when needed
calculator.clearPoints();
Parse GPX files to extract geographical points:
final calculator = ByRoadDistanceCalculator();
final gpxContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1">
<trk>
<trkseg>
<trkpt lat="37.7749" lon="-122.4194"></trkpt>
<trkpt lat="37.7850" lon="-122.4100"></trkpt>
<trkpt lat="37.7950" lon="-122.4000"></trkpt>
</trkseg>
</trk>
</gpx>
''';
final points = calculator.parseGPX(gpxContent);
final distance = calculator.calculateDistance(points);
print('Distance from GPX: $distance km');
Parse KML files to extract geographical points:
final calculator = ByRoadDistanceCalculator();
final kmlContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<LineString>
<coordinates>
-122.4194,37.7749,0
-122.4100,37.7850,0
-122.4000,37.7950,0
</coordinates>
</LineString>
</Placemark>
</Document>
</kml>
''';
final points = calculator.parseKML(kmlContent);
final distance = calculator.calculateDistance(points);
print('Distance from KML: $distance km');
Convert encoded polyline strings to geographical points:
final encodedPolyline = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
final points = ByRoadDistanceCalculator.decodePolylineString(encodedPolyline);
You can specify a custom OSRM server URL if you're hosting your own instance:
calculator.calculateDistanceViaOSRM(
start: start,
end: end,
mode: TravelModes.driving,
customOSRMUrl: 'https://your-custom-osrm-server.com/route/v1',
).then((result) {
print('Distance: ${result.distance} km');
});
This package depends on:
latlong2: For geographical coordinate operationshttp: For API requestsxml: For parsing GPX and KML filesThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Please file issues and feedback here.