latlong_to_place

A powerful Flutter library to handle all your geocoding, routing, and location-based needs. Convert latitude/longitude into rich PlaceInfo, calculate distances, get OSRM routes, check permissions, generate static map images, and more.
Features
- πΊοΈ Reverse Geocoding: Convert
lat,lngto a structuredPlaceInfoaddress, with optional caching and accuracy controls. - β‘οΈ Forward Geocoding: Convert address strings to
LatLngcoordinates andPlaceInfo. - π Search Autocomplete: Get live address suggestions with built-in debounce logic.
- πΊοΈ Static Map Generation: Easily create URLs for static map thumbnails (e.g., OpenStreetMap).
- π Batch Geocoding: Fetch multiple addresses in a single call.
- π¦ Location Permissions: A simple helper to check
granted,denied, andserviceDisabledstatuses. - π§ Geo-Fencing: Simple radius-based check to see if a point is inside a given area.
- π Multi-Stop Routing: Get the best route and turn-by-turn instructions for multiple waypoints via OSRM.
- π Distance Calculation: Measure distances between coordinates in KM, meters, or miles.
Installation
Add to your appβs pubspec.yaml:
dependencies:
latlong_to_place: ^0.0.9 # Use the latest version
API Showcase
1. Geocoding (Reverse, Forward, Batch & Cached)
The GeocodingService is your entry point for all address lookups.
final _geo = GeocodingService();
// Single Reverse Geocoding with caching
final PlaceInfo place = await _geo.getPlaceInfo(
28.6139,
77.2090,
useCache: true,
accuracy: AccuracyMode.high,
);
print('Reverse Geocoding: '+place.formattedAddress);
// Forward Geocoding: Address to Coordinates
final PlaceInfo coordinates = await _geo.getCoordinates(
'Eiffel Tower, Paris',
);
print('Forward Geocoding: '+coordinates.latitude.toString() + ', ' + coordinates.longitude.toString());
// Batch lookup
final List<PlaceInfo> places = await _geo.getPlacesInfo([
LatLng(28.61, 77.20),
LatLng(28.53, 77.39),
]);
print('Batch Reverse Geocoding: '+places.map((p) => p.city).toList());
// Search Autocomplete (typically used with a TextField onChange)
final List<PlaceInfo> suggestions = await _geo.searchSuggestions('New York');
print('Search Suggestions: '+suggestions.map((p) => p.formattedAddress).toList());
2. Location Permission Status
Check permissions easily before accessing location.
final LocationStatus status = await LocationService.checkStatus();
if (status == LocationStatus.granted) {
// Permission granted, proceed
} else {
// Handle denied, permanently denied, or disabled service
}
3. Multi-Stop Routing & Instructions
Get a route for multiple waypoints, including distance, duration, and turn-by-turn instructions.
final route = await RouteService.getBestRoute(
stops: [
LatLng(28.6139, 77.2090), // Delhi
LatLng(28.5355, 77.3910), // Noida
LatLng(28.4595, 77.0266), // Gurgaon
],
mode: TravelMode.driving,
);
if (route != null) {
print('Distance: ${route.distanceKm.toStringAsFixed(2)} km');
print('Duration: ${route.duration.inMinutes} mins');
print('Instructions: ${route.instructions.first}'); // e.g., "Turn left onto..."
}
4. Geo-Fencing
Check if a point is within a certain radius.
final bool isInside = GeoFence.isInside(
point: LatLng(28.61, 77.20),
center: LatLng(28.60, 77.19),
radiusMeters: 2000, // 2km radius
);
print('Is inside fence: $isInside');
5. Static Map Image Generation
Generate URLs for static map thumbnails.
final provider = OpenStreetMapProvider();
final centerPoint = LatLng(28.6139, 77.2090); // Example: Delhi
final staticMapUrl = provider.getStaticMapUrl(
center: centerPoint,
zoom: 13,
size: const Size(600, 400),
markerColor: 'red', // Optional marker color
);
print('Static Map URL: '+staticMapUrl);
// Use with Flutter's Image.network widget:
// Image.network(staticMapUrl, width: 300, height: 200, fit: BoxFit.cover)

Libraries
- latlong_to_place
- A Flutter package to convert device latitude/longitude into structured address information, and to calculate distances between multiple coordinates.