google_map_service 0.0.3
google_map_service: ^0.0.3 copied to clipboard
A Flutter package providing Google Maps services: map control, markers, polylines, geocoding, directions, and place APIs.
πΊοΈ Google Map Service for Flutter #
A complete Flutter package that wraps and simplifies Google Maps APIs into a clean, service-based architecture.
It provides easy-to-use methods for map interactions, directions, geocoding, places, and distance calculations β all using the official Google Maps Platform.
π Features #
- π§ Map Initialization β Effortlessly display and control Google Maps widgets.
- π Markers & Polylines Management β Add, update, and remove markers and polylines dynamically.
- πΊοΈ Geocoding / Reverse Geocoding β Convert between coordinates and addresses.
- π§ Places API Integration β Search, autocomplete, and get detailed place info.
- π£οΈ Directions API β Get routes, distances, and durations between two or more locations.
- π Distance Matrix API β Calculate travel distance and time for multiple origins/destinations.
- π Custom Map Styles β Apply dark/light/custom themes easily.
- β‘ Async, Null-safe, and Well-structured β Built for modern Flutter and Dart.
π¦ Installation #
Add the dependency to your pubspec.yaml:
dependencies:
google_map_service: ^0.0.1
Then run:
flutter pub get
π Setup #
-
Enable Google APIs
Make sure the following APIs are enabled on your Google Cloud Console:
- Maps SDK for Android
- Maps SDK for iOS
- Geocoding API
- Places API
- Directions API
- Distance Matrix API
-
Add your API key
In your
AndroidManifest.xml:<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY_HERE" />In your
AppDelegate.swift(iOS):GMSServices.provideAPIKey("YOUR_API_KEY_HERE") -
Initialize the service
import 'package:google_map_service/google_map_service.dart'; final mapService = GoogleMapService(apiKey: 'YOUR_API_KEY_HERE');
π§© API Usage #
πΊοΈ Displaying a Google Map #
GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(37.7749, -122.4194),
zoom: 12,
),
onMapCreated: mapService.onMapCreated,
markers: mapService.markers,
polylines: mapService.polylines,
);
π Add a Marker #
mapService.addMarker(
id: 'marker1',
position: LatLng(37.7749, -122.4194),
title: 'San Francisco',
snippet: 'California',
);
π§ Get Directions #
final route = await mapService.getDirections(
origin: LatLng(37.7749, -122.4194),
destination: LatLng(34.0522, -118.2437),
);
mapService.addPolylineFromDirections(route);
π Geocode an Address #
final coordinates = await mapService.geocodeAddress('1600 Amphitheatre Parkway, Mountain View, CA');
π« Reverse Geocode a Coordinate #
final address = await mapService.reverseGeocode(LatLng(37.4219999, -122.0840575));
π§ Place Autocomplete #
final results = await mapService.autocompletePlaces('Eiffel Tower');
βοΈ Configuration Options #
GoogleMapService(
apiKey: 'YOUR_API_KEY',
language: 'en',
region: 'US',
mapStyle: MapStyle.dark,
);
π Example App #
See /example folder for a complete Flutter demo using all APIs.
Run:
flutter run example/
π§ͺ Testing #
Mock services are included for unit testing.
final mockService = MockGoogleMapService();
π Permissions #
Add these permissions in your AndroidManifest.xml and Info.plist:
-
Android:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> -
iOS:
<key>NSLocationWhenInUseUsageDescription</key> <string>This app needs access to your location.</string>
π§° Supported Platforms #
- β Android
- β iOS
- β Web (limited APIs β requires JS Maps SDK)
π License #
This project is licensed under the MIT License β see the LICENSE file for details.
π‘ Contributing #
Pull requests are welcome!
Please make sure to:
- Write clear commit messages.
- Add documentation and test coverage for new features.
π Roadmap #
- β Support for custom map overlays
- β Offline maps support
- β Route optimization
- β Street View integration
π¨βπ» Author #
Raj kumar Patel
Flutter Developer | Open Source Contributor
π§ rajkumar07793@gmail.com