Example 1: flutter_map marker
class _MapDataState extends State<MapData> {
List<SitesList> sl = [];
List<SnoTelSite> sts = [];
var marker = <Marker>[];
_MapDataState(){
print("map data state");
loadSites().then((sitesdata) {
print('Loaded Sites Asset JSON');
sts..addAll(sitesdata);
sts.forEach((s) {
marker.add(
Marker(
point: new LatLng(double.parse(s.lat),double.parse(s.lng)),
builder: (ctx) => _MarkerPopUp(sitename: s.name, siteelevation: s.elevation, siteid: s.siteID,),
),
);
});
});
}
Future<String> _loadSiteAssets() async {
return await rootBundle.loadString(snotelsitesjson);
}
Future loadSites() async {
String jsonString = await _loadSiteAssets();
final jsonResponse = json.decode(jsonString);
SitesList sitesList = new SitesList.fromJson(jsonResponse);
return sitesList.sites;
}
@override
Widget build(BuildContext context) {
print("BUILD LAYOUT");
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.cyan,
),
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: Icon(Icons.ac_unit),
title: Text("SnoTel Map"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.favorite),
onPressed: () {
debugPrint("Favorites");
},
),
IconButton(
icon: Icon(Icons.feedback),
onPressed: () {
debugPrint("Message sent");
},
),
],
),
body: _MapWidget()),
);
}
}
Example 2: gooogle maps flutter
dependencies:
google_maps_flutter: ^0.5.28+1
Example 3: google maps for flutter
dependencies:
google_maps_flutter: ^1.0.2
Example 4: flutter draw google map
import 'package:google_maps_flutter/google_maps_flutter.dart';
static const LatLng _center = const LatLng(33.738045, 73.084488);
final Set<Marker> _markers = {};
final Set<Polyline>_polyline={};
LatLng _lastMapPosition = _center;
List<LatLng> latlng = List();
LatLng _new = LatLng(33.738045, 73.084488);
LatLng _news = LatLng(33.567997728, 72.635997456);
latlng.add(_new);
latlng.add(_news);
void _onAddMarkerButtonPressed() {
getDistanceTime();
setState(() {
_markers.add(Marker(
markerId: MarkerId(_lastMapPosition.toString()),
position: _lastMapPosition,
infoWindow: InfoWindow(
title: 'Really cool place',
snippet: '5 Star Rating',
),
icon: BitmapDescriptor.defaultMarker,
));
_polyline.add(Polyline(
polylineId: PolylineId(_lastMapPosition.toString()),
visible: true,
points: latlng,
color: Colors.blue,
));
});
GoogleMap(
polylines:_polyline,
markers: _markers,
onMapCreated: _onMapCreated,
myLocationEnabled:true,
onCameraMove: _onCameraMove,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
mapType: MapType.normal,
);
}