google_location_extract 1.0.0
google_location_extract: ^1.0.0 copied to clipboard
Extract rich location details from full and shortened Google Maps URLs.
google_location_extract #
A Flutter library for extracting useful information from Google Maps URLs. It
supports full links, maps.app.goo.gl short links, URLs embedded in shared text,
place links, search links, coordinate links, and directions links.
The result can include:
- original, expanded, and canonical Google Maps URLs
- latitude, longitude, and zoom
- place name, formatted address, Google place ID, and plus code
- search query
- directions origin, destination, and travel mode
- useful URL metadata such as map layer and action
It does not require a Google Maps API key. Details exposed only by Google APIs still require the relevant official API and credentials.
Add to an app #
dependencies:
google_location_extract:
path: ../google_location_extract
Then run flutter pub get.
Resolve and extract a shared link #
import 'package:google_location_extract/google_location_extract.dart';
final extractor = GoogleMapsLocationExtractor();
try {
final location = await extractor.extract(
'Meet me here: https://maps.app.goo.gl/example',
);
print(location.placeName);
print(location.address);
print('${location.latitude}, ${location.longitude}');
print(location.canonicalUrl);
print(location.toJson());
} finally {
extractor.close();
}
Short URLs require internet access because their redirect must be followed. HTML enrichment is best effort: a full URL still returns its URL-derived data if the request is unavailable.
Parse locally without networking #
const parser = GoogleMapsParser();
final location = parser.parse(
'https://www.google.com/maps/place/Accra+Mall/@5.6224,-0.1731,17z',
);
To resolve a short link but skip HTML enrichment, pass
fetchPageDetails: false to extract. Full links with that option are parsed
entirely offline.