Skip to content

Instantly share code, notes, and snippets.

@egeysn
Last active September 2, 2020 15:17
Show Gist options
  • Save egeysn/9288d4c7071d842c826e84d841cc44a4 to your computer and use it in GitHub Desktop.
Save egeysn/9288d4c7071d842c826e84d841cc44a4 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import "locations.dart" as locations;
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final Map<String, Marker> _markers = {};
Future<void> _onMapCreated(GoogleMapController controller) async {
final googleOffices = await locations.getGoogleOffices();
setState(() {
_markers.clear();
for (final office in googleOffices.offices) {
final marker = Marker(
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) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('Google Maps App'),
backgroundColor: Colors.green[700],
),
body: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: LatLng(41.2878742, 36.326696),
zoom: 6,
),
markers: _markers.values.toSet(),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment