extractLocationInfo static method
Extracts comprehensive location information from a Google Maps URL.
This method combines multiple extraction methods to provide a complete set of location information from the URL.
Returns a Map containing all available location information:
- 'latitude': double
- 'longitude': double
- 'zoom': int (if available)
- 'placeName': String (if available)
- 'urlType': String (describes the type of URL)
Example usage:
final url = 'https://www.google.com/maps/place/Eiffel+Tower/@48.8583701,2.2922926,17z';
final info = GoogleMapsUrlExtractor.extractLocationInfo(url);
if (info != null) {
print('Latitude: ${info['latitude']}');
print('Longitude: ${info['longitude']}');
print('Zoom: ${info['zoom']}');
print('Place: ${info['placeName']}');
print('Type: ${info['urlType']}');
}
Implementation
static Map<String, dynamic>? extractLocationInfo(String url) {
final coordinates = extractCoordinates(url);
if (coordinates == null) return null;
final zoom = extractZoomLevel(url);
final placeName = extractPlaceName(url);
// Determine URL type
String urlType = 'unknown';
if (url.contains('/place/')) {
urlType = 'place';
} else if (url.contains('/search/')) {
urlType = 'search';
} else if (url.contains('/dir/')) {
urlType = 'directions';
} else if (url.contains('@')) {
urlType = 'map';
}
final result = <String, dynamic>{
'latitude': coordinates['latitude'],
'longitude': coordinates['longitude'],
'urlType': urlType,
};
if (zoom != null) result['zoom'] = zoom;
if (placeName != null) result['placeName'] = placeName;
return result;
}