Last active
October 12, 2023 07:45
-
-
Save iam111/9668cb4ee273b65b5d9c608b94e1d85b to your computer and use it in GitHub Desktop.
Custom Google Map Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set<Marker> markerLocations = <Marker>{ | |
const Marker( | |
markerId: MarkerId('location1'), | |
position: LatLng(37.483210, -122.145176), | |
), | |
const Marker( | |
markerId: MarkerId('location2'), | |
position: LatLng(37.482144, -122.144668), | |
) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
class CustomMapSample extends StatefulWidget { | |
const CustomMapSample({super.key}); | |
@override | |
State<CustomMapSample> createState() => CustomMapSampleState(); | |
} | |
class CustomMapSampleState extends State<CustomMapSample> { | |
final Completer<GoogleMapController> _controller = | |
Completer<GoogleMapController>(); | |
Set<Marker> markerLocations = <Marker>{ | |
const Marker( | |
markerId: MarkerId('location1'), | |
position: LatLng(37.483210, -122.145176), | |
), | |
const Marker( | |
markerId: MarkerId('location2'), | |
position: LatLng(37.482144, -122.144668), | |
) | |
}; | |
static const CameraPosition nearMetaHeadquarters = CameraPosition( | |
target: LatLng(37.483498, -122.144196), | |
zoom: 15, | |
); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text("Map Sample"),), | |
body: GoogleMap( | |
mapType: MapType.normal, | |
initialCameraPosition: nearMetaHeadquarters, | |
markers: markerLocations, //******ADD THIS ********* | |
onMapCreated: (GoogleMapController controller) { | |
_controller.complete(controller); | |
}, | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
class CustomMapSample extends StatefulWidget { | |
const CustomMapSample({super.key}); | |
@override | |
State<CustomMapSample> createState() => CustomMapSampleState(); | |
} | |
class CustomMapSampleState extends State<CustomMapSample> { | |
final Completer<GoogleMapController> _controller = | |
Completer<GoogleMapController>(); | |
Set<Marker> markerLocations = {}; | |
static const CameraPosition nearMetaHeadquarters = CameraPosition( | |
target: LatLng(37.483498, -122.144196), | |
zoom: 15, | |
); | |
@override | |
void initState() { | |
// TODO: implement initState | |
super.initState(); | |
setMarkers(); | |
} | |
Future<void> setMarkers() async { | |
markerLocations = <Marker>{ | |
Marker( | |
icon: await BitmapDescriptor.fromAssetImage(const ImageConfiguration(size: Size(5, 5)), 'assets/free.png'), | |
markerId: MarkerId('location1'), | |
position: LatLng(37.483210, -122.145176), | |
), | |
Marker( | |
icon: await BitmapDescriptor.fromAssetImage(const ImageConfiguration(size: Size(5, 5)), 'assets/delivery_bike.png'), | |
markerId: MarkerId('location2'), | |
position: LatLng(37.482144, -122.144668), | |
) | |
}; | |
setState(() { | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text("Map Sample"),), | |
body: GoogleMap( | |
mapType: MapType.normal, | |
initialCameraPosition: nearMetaHeadquarters, | |
markers: markerLocations!, | |
onMapCreated: (GoogleMapController controller) { | |
_controller.complete(controller); | |
}, | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
class CustomMapSample extends StatefulWidget { | |
const CustomMapSample({super.key}); | |
@override | |
State<CustomMapSample> createState() => CustomMapSampleState(); | |
} | |
class CustomMapSampleState extends State<CustomMapSample> { | |
final Completer<GoogleMapController> _controller = | |
Completer<GoogleMapController>(); | |
static const CameraPosition nearMetaHeadquarters = CameraPosition( | |
target: LatLng(37.483498, -122.144196), | |
zoom: 15, | |
); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text("Map Sample"),), | |
body: GoogleMap( | |
mapType: MapType.normal, | |
initialCameraPosition: nearMetaHeadquarters, | |
onMapCreated: (GoogleMapController controller) { | |
_controller.complete(controller); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment