google_map_drawer 0.0.1
google_map_drawer: ^0.0.1 copied to clipboard
A Flutter package to draw polygons on Google Maps and manage locations easily.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:google_map_drawer/google_map_drawer.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MapExample(),
);
}
}
class MapExample extends StatefulWidget {
@override
State<MapExample> createState() => _MapExampleState();
}
class _MapExampleState extends State<MapExample> {
final GoogleMapDrawController mapController = GoogleMapDrawController();
// Example locations
final List<LocationInfo> locations = [
LocationInfo(
name: "My Home",
position: LatLng(11.5564, 104.9282),
address: "Phnom Penh",
distanceFromUser: 2.5,
),
LocationInfo(
name: "Office",
position: LatLng(11.5620, 104.9270),
address: "Central Phnom Penh",
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Google Map Drawer Example")),
body: Stack(
children: [
GoogleMapDrawer(
controller: mapController,
polygonColor: Colors.blue,
polygonOpacity: 0.3,
initialCamera: const CameraPosition(
target: LatLng(11.5564, 104.9282),
zoom: 14,
),
),
// You can add markers manually using a separate layer if needed
],
),
floatingActionButton: FloatingActionButton.extended(
icon: const Icon(Icons.save),
label: const Text("Save Area"),
onPressed: () {
mapController.saveArea("My Property");
print("Saved Areas:");
for (var area in mapController.savedAreas) {
print(area.toJson());
}
},
),
);
}
}