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={};

//add your lat and lng where you wants to draw 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);

//call this method on button click that will draw a polyline and markers

void _onAddMarkerButtonPressed() {
    getDistanceTime();
    setState(() {
        _markers.add(Marker(
            // This marker id can be anything that uniquely identifies each marker.
            markerId: MarkerId(_lastMapPosition.toString()),
            //_lastMapPosition is any coordinate which should be your default 
            //position when map opens up
            position: _lastMapPosition,
            infoWindow: InfoWindow(
                title: 'Really cool place',
                snippet: '5 Star Rating',
            ),
            icon: BitmapDescriptor.defaultMarker,

        ));
        _polyline.add(Polyline(
            polylineId: PolylineId(_lastMapPosition.toString()),
            visible: true,
            //latlng is List<LatLng>
            points: latlng,
            color: Colors.blue,
        ));
    });

    //in your build widget method
    GoogleMap(
    //that needs a list<Polyline>
        polylines:_polyline,
        markers: _markers,
        onMapCreated: _onMapCreated,
        myLocationEnabled:true,
        onCameraMove: _onCameraMove,
        initialCameraPosition: CameraPosition(
            target: _center,
            zoom: 11.0,
        ),

        mapType: MapType.normal,

    );
}

Are there any code examples left?
New code examples in category Go
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
draw over google maps flutter flutter draw over google map draw map how to get there via flutter google map flutter open in google maps draw anotatons google map flutter import GoogleMapPolyline flutter google map inside the flutter app polylines flutter multiple stopd how to draw polyline between two markers flutter polgon route show flutter how to draw polyline on google map between 3 markes in flutter Click two or more points on the map to draw polylines. flutter google map with flutter google maps flutter flutter with google maps polyline between two coordinates flutter add road on google direction flutter show road on google direction flutter display route maps direction flutter multi color of routes of google map in flutter multi color of polyline of google map in flutter flutter polylines doesnt follow route flutter google maps marker google map flutter example google maps in flutter destination_map_marker flutter flutter route lines google maps google map polyline not showing flutter make route on google maps flutter flutter google maps draw route google maps flutter get route show a path on map flutter flutter draw route to the map flutter google direction api build polyline path between 2 points flutter draw route on google maps flutter example flutter google poly lines example how show road value on direction google maps flutter why polylines returns to startting point fluter maps flutter polylines google maps example show multiple polylines on google map flutter draw route on google maps flutter google maps flutter polyline examples google maps flutter polyline flutter google map display route waypoints add marker flutter draw direction between location flutter show directions line with google map flutter show map directions between 2 places flutter draw line between two points flutter create routing between origin and destination on flutter draw route between two locations android flutter how to draw a map flutter polyline points.getroutebetweencoordinates how to draw a route to a place using its coodinates on google map on flutter drawing street map with custom coordinates flutter drawing route lines on google maps between two locations in flutter how to draw line on two location googlemap flutter flutter draw routes with vehicule googlemaps PolylineResult flutter create custom route in flutter map google map polylines overlapping routes flutter flutter google maps make a route flutter map drawer plygon for a route in flutter plot places on a map in flutter plot markers on route in flutter route boxer in dart route boxer for google map in flutter drawing map flutter flutter draw google map
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source