Created
July 24, 2022 08:30
-
-
Save rajesh-h/916cfc21e31fa3d0625595a70df95088 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'package:flutter/material.dart'; | |
import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
import 'package:ugv_fe/models/locations.dart' as locations; | |
class MapsView extends StatefulWidget { | |
const MapsView({Key? key}) : super(key: key); | |
@override | |
State<MapsView> createState() => _MapsViewState(); | |
} | |
class _MapsViewState extends State<MapsView> { | |
final Map<String, Marker> _markers = {}; | |
BitmapDescriptor? myMarker; | |
void setMarkerIcon() async { | |
myMarker = await BitmapDescriptor.fromAssetImage( | |
const ImageConfiguration(size: Size(50, 50)), | |
'assets/images/ugv_icon1.png'); | |
} | |
static const CameraPosition _kGooglePlex = CameraPosition( | |
target: LatLng(3.738692, 103.191214), | |
zoom: 18, | |
); | |
Future<void> _onMapCreated(GoogleMapController controller) async { | |
final googleOffices = await locations.getGoogleOffices(); | |
setState(() { | |
_markers.clear(); | |
for (final office in googleOffices.offices) { | |
final marker = Marker( | |
icon: myMarker, | |
markerId: MarkerId(office.name), | |
position: LatLng(office.lat, office.lng), | |
infoWindow: InfoWindow( | |
title: office.name, | |
snippet: office.address, | |
), | |
); | |
_markers[office.name] = marker; | |
} | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
setMarkerIcon(); | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('UGV Positions'), | |
automaticallyImplyLeading: false, | |
backgroundColor: Colors.green[700], | |
), | |
body: GoogleMap( | |
mapType: MapType.hybrid, | |
onMapCreated: _onMapCreated, | |
initialCameraPosition: _kGooglePlex, | |
markers: _markers.values.toSet(), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment