google_places_native_sdk 3.0.0
google_places_native_sdk: ^3.0.0 copied to clipboard
A Flutter plugin for Google Places SDK.
Google Places Native SDK 🌍 #
A powerful, high-performance Flutter plugin that integrates Google Places SDK directly with native APIs for Android and iOS. Build beautiful, location-aware applications with real-time prediction and detailed place information.
📱 Version Compatibility #
| Package Version | Flutter Version |
|---|---|
| 1.0.0 | 3.24.x |
| 2.0.0 | 3.29.x |
| 3.0.0 | 3.38.x |
✨ Features #
| Feature | Description |
|---|---|
| 🔍 Autocomplete | Real-time prediction as you type, powered by native Google Places API. |
| 📍 Place Details | Fetch rich details including coordinates, address, and place IDs. |
| 🛡️ Native Security | Uses native Android and iOS SDKs, ensuring API key restrictions work correctly. |
| ⚡ Performance | Optimized MethodChannels for blazing fast response times. |
| 🛠️ Easy Integration | Simple API design that fits perfectly into any Flutter workflow. |
🚀 Installation #
Add this to your package's pubspec.yaml file:
dependencies:
google_places_native_sdk: ^3.0.0
Or run:
flutter pub add google_places_native_sdk
⚙️ Configuration #
To use this plugin, you need to configure your Google Maps/Places API keys in your native project files.
Important: Ensure you have enabled the following APIs in your Google Cloud Console:
- Maps SDK for Android
- Maps SDK for iOS
- Places API (New)
🤖 Android #
- Open
android/app/src/main/AndroidManifest.xml. - Add your API key inside the
<application>tag:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_ANDROID"/>
Security Recommendation:
- Restrict your Android API key in the Google Cloud Console.
- Application restriction: Android apps (Use your package name and SHA-1 certificate fingerprint).
- API restriction: Select ONLY Maps SDK for Android and Places API (New).
🍎 iOS #
- Open
ios/Runner/AppDelegate.swift. - Import GoogleMaps and provide your API key:
import GoogleMaps
GMSServices.provideAPIKey("YOUR_API_KEY_IOS")
Security Recommendation:
- Restrict your iOS API key in the Google Cloud Console.
- Application restriction: iOS apps (Use your app's Bundle Identifier).
- API restriction: Select ONLY Maps SDK for iOS and Places API (New).
💡 How to Use #
Quick Start: Initialize the SDK with your API key and start making requests!
import 'package:google_places_native_sdk/google_places_native_sdk.dart';
import 'dart:io' show Platform;
void main() async {
// 1. Initialize the SDK
// It is recommended to use different API keys for Android and iOS
String apiKey = Platform.isAndroid
? 'YOUR_API_KEY_ANDROID'
: 'YOUR_API_KEY_IOS';
await PlacesChannel.initialize(apiKey);
// 2. Search for places
try {
final predictions = await PlacesChannel.getAutocompletePredictions("Paris");
print("Found ${predictions.length} results");
} catch (e) {
print("Error: $e");
}
}
🔍 Detailed Usage Examples #
Search for a Place (Autocomplete)
Get real-time predictions as the user types.
final predictions = await PlacesChannel.getAutocompletePredictions("San Fran");
for (var p in predictions) {
print("${p.primaryText} - ${p.placeId}");
}
Get Place Details
Fetch coordinates and address for a selected place.
final details = await PlacesChannel.getPlaceDetails("ChIJIQBpAG2ahYAR_6128GcTUEo");
print("Selected: ${details.name}");
print("Location: ${details.latitude}, ${details.longitude}");
📱 Example App #
Check out the example/ folder for a complete Demo Application that features:
- Glassmorphic Search UI
- Google Maps Integration
- Live Location Tracking
- Custom Markers
🤝 Contributing #
Contributions are welcome! If you find a bug or want a feature, please open an issue.
📄 License #
This project is licensed under the MIT License - see the LICENSE file for details.