Created
May 5, 2019 08:52
-
-
Save RajaShanmugamJM/7f9ed7bcf43e82616bf6e16ce66216f1 to your computer and use it in GitHub Desktop.
Polyline support in Google Maps Flutter
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 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:google_maps_flutter/google_maps_flutter.dart'; | |
void main() => runApp(Main()); | |
class Main extends StatefulWidget { | |
@override | |
_MainState createState() => _MainState(); | |
} | |
class _MainState extends State<Main> { | |
Set<Polyline> lines = {}; | |
Completer<GoogleMapController> _controller = Completer(); | |
static final CameraPosition _kGooglePlex = CameraPosition( | |
target: LatLng(12.988827, 77.472091), | |
zoom: 13 | |
); | |
@override | |
void initState() { | |
super.initState(); | |
lines.add( | |
Polyline( | |
points: [ | |
LatLng(12.988827, 77.472091), | |
LatLng(12.980821, 77.470815), | |
LatLng(12.969406, 77.471301) | |
], | |
endCap: Cap.squareCap, | |
geodesic: false, | |
polylineId: PolylineId("line_one"), | |
), | |
); | |
lines.add( | |
Polyline( | |
points: [LatLng(12.949798, 77.470534), LatLng(12.938614, 77.469379)], | |
color: Colors.amber, | |
polylineId: PolylineId("line_one"), | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Google Maps Polylines', | |
home: Scaffold( | |
body: GoogleMap( | |
mapType: MapType.normal, | |
myLocationEnabled: true, | |
initialCameraPosition: _kGooglePlex, | |
onMapCreated: (GoogleMapController controller) { | |
_controller.complete(controller); | |
}, | |
polylines: lines, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment