latlong_to_place 0.0.9 copy "latlong_to_place: ^0.0.9" to clipboard
latlong_to_place: ^0.0.9 copied to clipboard

A Flutter library to fetch device LatLng via geolocator and convert it into rich PlaceInfo via the null-safe geocoding plugin.

latlong_to_place #

Top Banner

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,lng to a structured PlaceInfo address, with optional caching and accuracy controls.
  • ➑️ Forward Geocoding: Convert address strings to LatLng coordinates and PlaceInfo.
  • πŸ” 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, and serviceDisabled statuses.
  • 🚧 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)

Bottom Banner

4
likes
150
points
253
downloads

Publisher

verified publisherarpitjai.com

Weekly Downloads

A Flutter library to fetch device LatLng via geolocator and convert it into rich PlaceInfo via the null-safe geocoding plugin.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, geocoding, geolocator, http, latlong2

More

Packages that depend on latlong_to_place