To add markers to the map in your project, perform the following steps:
- Get back to the Google Maps API console and enable the places API for your app. Make sure that your Flutter Maps project is selected, and then click the Enable button.
- At the top of the main.dart file, add two new imports, one for http and another for the dart:convert package, as shown here:
import 'package:http/http.dart' as http;
import 'dart:convert';
- At the top of the _MyMapState class, and a new List of Marker objects:
class _MyMapState extends State<MyMap> {
LatLng userPosition;
List<Marker> markers = [];
- In the AppBar contained in the build method of the _MyMapState class, add the actions property, containing an IconButton, which, when pressed, calls a findPlaces method that we will create in the next steps:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Google Maps'),
actions...