map_services 0.0.1
map_services: ^0.0.1 copied to clipboard
A Flutter package for mapping services including distance calculation, reverse geocoding, and routing.
map_services is a Flutter package that provides easy-to-use services for common mapping tasks such as distance calculation, reverse geocoding, and route fetching.
Features #
- Reverse Geocoding: Convert coordinates (Latitude/Longitude) into human-readable addresses using Nominatim (OSM).
- Distance Calculation: Calculate the distance between two geographical points using the Haversine formula.
- Radius Check: Easily determine if a point is within a specified radius of another point.
- Route Fetching: Get route points between two locations using OSRM.
- Address Search: Search for addresses using the Photon API.
Getting started #
Add map_services to your pubspec.yaml:
dependencies:
map_services:
path: path/to/map_services
Usage #
Distance Calculation #
final mapServices = MapServices();
final pointA = LatLong(14.5995, 120.9842); // Manila
final pointB = LatLong(14.5547, 121.0244); // Makati
double distance = mapServices.getDistanceInKm(pointA: pointA, pointB: pointB);
print('Distance: $distance km');
bool isClose = mapServices.isWithinRadius(center: pointA, target: pointB, radiusKm: 10.0);
print('Is within 10km: $isClose');
Address Search #
final results = await MapServices.searchAddress('Manila');
for (var result in results) {
print('Found: ${result.address} at ${result.latitude}, ${result.longitude}');
}
Detail examples can be found in the /example folder.
Security & Configuration #
To avoid hardcoding URLs in your binary, you can configure them using a .env file.
The package comes with a default map_service.env file in its root. This file contains the default service URLs. Because these are managed as package assets, you don't need to perform any extra setup to use the default services.
If you need to override these URLs for your own private backend or proxy, you can still use the MapServices.setTestConfig() method or provide your own .env file management if you fork the package.
Additional information #
This package uses public APIs like Nominatim, OSRM, and Photon. Please respect their usage policies.