Search packages, repositories and app categories

GitHub repositoryflutterbuddy1/geocoder2

geocoder2

flutterbuddy1/geocoder2 open-source repository details.

geocoder2 project cover
Stars
4
Forks
27
Last push (UTC)
Sep 18, 2026
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

geocoder2

Easy forward and reverse geocoding from the Google Maps Geocoding API for Flutter & Dart.

Make sure to enable the Geocoding API for your project in the Google Cloud Console.


Features

  • 🚀 Modern & Compatible: Supports Flutter 3.x and Dart 3.x with http: ">=0.13.4 <2.0.0".
  • 🔍 Forward Geocoding: Convert address strings into coordinates and structured location data.
  • 📍 Reverse Geocoding: Convert latitude and longitude coordinates into human-readable addresses.
  • 📋 Multiple Results Support: Retrieve all matching address candidates via getAllDataFromAddress / getAllDataFromCoordinates.
  • 🛡️ Zero Runtime Crashes: Full null-safety protection against missing fields, unknown location types, and empty results.
  • ⚠️ Clear Exception Handling: Structured Geocoder2Exception provides Google API status codes (REQUEST_DENIED, OVER_QUERY_LIMIT, ZERO_RESULTS, etc.) and error messages.
  • 🌐 Localization: Request address components in your preferred language using the optional language parameter.

Installation

Add geocoder2 to your pubspec.yaml:

dependencies:
  geocoder2: ^1.5.0

Code Examples

import 'package:geocoder2/geocoder2.dart';
Reverse Geocoding (Coordinates to Address)
try {
  GeoData data = await Geocoder2.getDataFromCoordinates(
    latitude: 40.714224,
    longitude: -73.961452,
    googleMapApiKey: "YOUR_GOOGLE_MAP_API_KEY",
    language: "en", // Optional language code
  );

  print("Address: ${data.address}");
  print("City: ${data.city}");
  print("State: ${data.state}");
  print("Country: ${data.country} (${data.countryCode})");
  print("Postal Code: ${data.postalCode}");
  print("Street Number: ${data.streetNumber}");
  print("Latitude: ${data.latitude}");
  print("Longitude: ${data.longitude}");
} on Geocoder2Exception catch (e) {
  print("Geocoding failed: ${e.message} (Status: ${e.status})");
}
Forward Geocoding (Address to Coordinates)
try {
  GeoData data = await Geocoder2.getDataFromAddress(
    address: "277 Bedford Ave, Brooklyn, NY 11211, USA",
    googleMapApiKey: "YOUR_GOOGLE_MAP_API_KEY",
  );

  print("Formatted Address: ${data.address}");
  print("Latitude: ${data.latitude}");
  print("Longitude: ${data.longitude}");
  print("City: ${data.city}");
} on Geocoder2Exception catch (e) {
  print("Geocoding failed: ${e.message} (Status: ${e.status})");
}
Get Multiple Address Matches
List<GeoData> results = await Geocoder2.getAllDataFromAddress(
  address: "Springfield",
  googleMapApiKey: "YOUR_GOOGLE_MAP_API_KEY",
);

for (var result in results) {
  print("${result.address} -> (${result.latitude}, ${result.longitude})");
}
Safe Nullable Queries

If you prefer null over catching an exception when no results exist:

GeoData? data = await Geocoder2.getDataFromAddressOrNull(
  address: "Some Rare Location",
  googleMapApiKey: "YOUR_GOOGLE_MAP_API_KEY",
);

if (data != null) {
  print("Found: ${data.address}");
} else {
  print("No address found.");
}

Language Support

Both forward and reverse methods support an optional language parameter. See the list of supported Google Maps language codes.


Alternative (OpenStreetMap / No API Key)

If you do not have a Google Maps API Key or want to use free OpenStreetMap Nominatim, check out geocoder_buddy.


Buy Me A Coffee

Buy Me A Coffee
Mayank Diwakar GitHub avatar
GitHub author

Mayank Diwakar ↗

Full-Stack Developer | Building modern, scalable applications with Flutter, React, Node.js, Laravel, PHP & more. 🚀

LanguagesDart

Dependencies used

Dependency list 4 items

  • flutter{"sdk":"flutter"}
  • http>=0.13.4 <2.0.0
  • flutter_testDevelopment{"sdk":"flutter"}
  • flutter_lintsDevelopment^2.0.0

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗