{"id":1561,"date":"2021-06-17T10:04:23","date_gmt":"2021-06-17T10:04:23","guid":{"rendered":"https:\/\/www.confianzit.com\/cit-blog\/?p=1561"},"modified":"2022-10-31T17:53:27","modified_gmt":"2022-10-31T17:53:27","slug":"using-google-maps-in-flutter","status":"publish","type":"post","link":"https:\/\/www.confianzit.com\/cit-blog\/using-google-maps-in-flutter\/","title":{"rendered":"Using Google Maps in Flutter"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; module_class=&#8221;blog-left-content&#8221; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_row column_structure=&#8221;2_3,1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">Today we will see a brief walkthrough on how to use Google Maps with Flutter, using the official google_maps_flutter plugin that is provided by the Flutter team itself. Normally using Flutter plugins are quite straightforward and require only a package install with maybe configuring some things at the native level code. However, in this article we will try to implement some of the APIs available in the package and see how it can be used in practice.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">As always, we will start from scratch by creating a new Flutter project and then adding the google_maps_flutter package. A caveat to using this package is that since we are working with Google Maps in the app, we would need a Google Maps API key. For that, you will have to create a project on Google Cloud Platform and enable the maps API. This will require using your credit card or some other form of payment registration, but it will provide free usage of Google Maps up to $200, which should be more than enough for our purposes. For more info on this check out the official Google Maps documentation (https:\/\/developers.google.com\/maps\/gmp-get-started).<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">After setting up the project and getting our API key, we can start by creating a new project and installing the package using <\/span><i><span style=\"font-weight: 400;\">flutter pub get google_maps_flutter<\/span><\/i><span style=\"font-weight: 400;\">. As mentioned before, we will need to make some changes in the native level code which are detailed below.<\/span><\/p>\n<p><b>For <a href=\"https:\/\/www.confianzit.com\/android-application-development\">Android<\/a>:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Set the minSdkVersion in android\/app\/build.gradle to 20<\/span><span style=\"font-weight: 400;\"><\/span><\/li>\n<\/ol>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243; saved_tabs=&#8221;all&#8221;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">android {\n    defaultConfig {\n        minSdkVersion 20\n    }\n}\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_code _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; locked=&#8221;off&#8221;]<\/p>\n<div class=\"blog-floating-form\"><!-- [et_pb_line_break_holder] -->  <\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.confianzit.com\/cit-blog\/using-google-maps-in-flutter\/#Talk_to_our_experts_now\" title=\"    Talk to our experts now  \">    Talk to our experts now  <\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.confianzit.com\/cit-blog\/using-google-maps-in-flutter\/#Talk_To_Our_Experts_Now\" title=\"Talk To Our Experts Now\n\t\">Talk To Our Experts Now\n\t<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"Talk_to_our_experts_now\"><\/span><!-- [et_pb_line_break_holder] -->    Talk to our experts now<!-- [et_pb_line_break_holder] -->  <span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><!-- [et_pb_line_break_holder] -->  \n<div class=\"wpcf7 no-js\" id=\"wpcf7-f1888-o1\" lang=\"en-US\" dir=\"ltr\">\n<div class=\"screen-reader-response\"><p role=\"status\" aria-live=\"polite\" aria-atomic=\"true\"><\/p> <ul><\/ul><\/div>\n<form action=\"\/cit-blog\/wp-json\/wp\/v2\/posts\/1561#wpcf7-f1888-o1\" method=\"post\" class=\"wpcf7-form init\" aria-label=\"Contact form\" novalidate=\"novalidate\" data-status=\"init\">\n<div style=\"display: none;\">\n<input type=\"hidden\" name=\"_wpcf7\" value=\"1888\" \/>\n<input type=\"hidden\" name=\"_wpcf7_version\" value=\"5.8.6\" \/>\n<input type=\"hidden\" name=\"_wpcf7_locale\" value=\"en_US\" \/>\n<input type=\"hidden\" name=\"_wpcf7_unit_tag\" value=\"wpcf7-f1888-o1\" \/>\n<input type=\"hidden\" name=\"_wpcf7_container_post\" value=\"0\" \/>\n<input type=\"hidden\" name=\"_wpcf7_posted_data_hash\" value=\"\" \/>\n<input type=\"hidden\" name=\"_wpcf7_recaptcha_response\" value=\"\" \/>\n<\/div>\n<div class=\"form-block\" style=\"    background: #fff;\">\n\t<h3 style=\"    background: #0C2464;\n    border-bottom: 5px solid #cecece;\n    border-radius: 5px 5px 90px 90px;\n    margin: 0 auto;\n    text-align: center;\n    padding: 20px;\n    color: #fff;    margin-bottom: 15px;\"><span class=\"ez-toc-section\" id=\"Talk_To_Our_Experts_Now\"><\/span><b>Talk To Our Experts Now<\/b>\n\t<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\t<div style=\"padding:20px;\">\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"your-name\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-text wpcf7-validates-as-required your-name\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Name\" value=\"\" type=\"text\" name=\"your-name\" \/><\/span>\n\t\t<\/p>\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"your-email\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-email wpcf7-validates-as-required wpcf7-text wpcf7-validates-as-email your-email\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Email\" value=\"\" type=\"email\" name=\"your-email\" \/><\/span>\n\t\t<\/p>\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"your-number\"><input size=\"40\" class=\"wpcf7-form-control wpcf7-tel wpcf7-validates-as-required wpcf7-text wpcf7-validates-as-tel your-number\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Phone Number\" value=\"\" type=\"tel\" name=\"your-number\" \/><\/span>\n\t\t<\/p>\n\t\t<p><span class=\"wpcf7-form-control-wrap\" data-name=\"message\"><textarea cols=\"40\" rows=\"10\" class=\"wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required form-message\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"Message\" name=\"message\"><\/textarea><\/span>\n\t\t<\/p>\n\t<span class=\"wpcf7-form-control-wrap recaptcha\" data-name=\"recaptcha\"><span data-sitekey=\"6LfFkQATAAAAAIYlZ_UH9UozO-OLkpAaWPWx6QtM\" class=\"wpcf7-form-control wpcf7-recaptcha g-recaptcha\"><\/span>\r\n<noscript>\r\n\t<div class=\"grecaptcha-noscript\">\r\n\t\t<iframe loading=\"lazy\" src=\"https:\/\/www.google.com\/recaptcha\/api\/fallback?k=6LfFkQATAAAAAIYlZ_UH9UozO-OLkpAaWPWx6QtM\" frameborder=\"0\" scrolling=\"no\" width=\"310\" height=\"430\">\r\n\t\t<\/iframe>\r\n\t\t<textarea name=\"g-recaptcha-response\" rows=\"3\" cols=\"40\" placeholder=\"reCaptcha Response Here\">\r\n\t\t<\/textarea>\r\n\t<\/div>\r\n<\/noscript>\r\n<\/span>\n\t\t<div class=\"form-buttons\">\n\t\t\t<p><input class=\"wpcf7-form-control wpcf7-submit has-spinner\" type=\"submit\" value=\"Get a free quote\" \/>\n\t\t\t<\/p>\n\t\t<\/div>\n\t<\/div>\n<\/div><div class=\"wpcf7-response-output\" aria-hidden=\"true\"><\/div>\n<\/form>\n<\/div>\n<!-- [et_pb_line_break_holder] --><\/div>\n<p>[\/et_pb_code][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">2. Specify the API key that you got from the Google Cloud console for Maps in android\/app\/src\/main\/AndroidManifest.xml file<\/span><\/p>\n<p><span style=\"font-weight: 400\"><\/span><\/p>\n<p><span style=\"font-weight: 400\"><\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">&lt;manifest ...<br \/>&lt;application ...<br \/>&lt;meta-data android:name=\"com.google.android.geo.API_KEY\"<br \/>android:value=\"YOUR KEY HERE\"\/&gt;<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><b>For <a href=\"https:\/\/www.confianzit.com\/ios-application-development\">iOS<\/a>:<\/b><\/p>\n<p><span style=\"font-weight: 400\">Specify the API key for Google maps in the AppDelegate file as shown below.<\/span><\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">For Objective C<\/span><\/li>\n<\/ol>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">#include \"AppDelegate.h\"\n#include \"GeneratedPluginRegistrant.h\"\n#import \"GoogleMaps\/GoogleMaps.h\"\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application\ndidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n[GMSServices provideAPIKey:@\"YOUR KEY HERE\"];\n[GeneratedPluginRegistrant registerWithRegistry:self];\nreturn [super application:application didFinishLaunchingWithOptions:launchOptions];\n}\n@end<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><b>For iOS:<\/b><\/p>\n<p><span style=\"font-weight: 400\">Specify the API key for Google maps in the AppDelegate file as shown below.<\/span><\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">For Objective C<\/span><\/li>\n<\/ol>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">#include \"AppDelegate.h\"\n#include \"GeneratedPluginRegistrant.h\"\n#import \"GoogleMaps\/GoogleMaps.h\"\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application\ndidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n[GMSServices provideAPIKey:@\"YOUR KEY HERE\"];\n[GeneratedPluginRegistrant registerWithRegistry:self];\nreturn [super application:application didFinishLaunchingWithOptions:launchOptions];\n}\n@end<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">2. For Swift<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">import UIKit\nimport Flutter\nimport GoogleMaps\n\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n  override func application(\n    _ application: UIApplication,\n    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n  ) -&gt; Bool {\n    GMSServices.provideAPIKey(\"YOUR KEY HERE\")\n    GeneratedPluginRegistrant.register(with: self)\n    return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n  }\n}\n\n\n\n\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">To proceed, we will set up the Maps at the home page itself. The <\/span><i><span style=\"font-weight: 400\">google_maps_flutter<\/span><\/i><span style=\"font-weight: 400\"> package should expose a GoogleMaps widget which we should be able to use to view the map.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">import 'package:flutter\/material.dart';\nimport 'package:google_maps_flutter\/google_maps_flutter.dart';\n \nvoid main() =&gt; runApp(MyApp());\n \nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      title: 'Flutter Google Maps Demo',\n      home: MapPage(),\n    );\n  }\n}\n \n \nclass MapPage extends StatefulWidget {\n  @override\n  State createState() =&gt; MapPageState();\n}\n \n \nclass MapPageState extends State {\n  static final CameraPosition _initialCameraPosition = CameraPosition(\n    target: LatLng(35.22690877158998, -80.84422853576228),\n    zoom: 16,\n  );\n \n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Stack(\n        children: [\n          GoogleMap(\n            mapType: MapType.normal,\n            initialCameraPosition: _initialCameraPosition,\n            onMapCreated: (GoogleMapController controller) {\n              _controller.complete(controller);\n            },\n            zoomControlsEnabled: false,\n          ),\n        ],\n      ),\n    );\n  }\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">A few things we need to notice here are:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">We need to specify the initial position to be shown on the map when it is initialized. Normally, we would make it use the current position of our device but for right now we can hard code a random position.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The onMapCreated property is not required per se for working on the widget, but we will need a reference to the GoogleMapController instance after the map is initialized for using other features of the maps such as markers and polylines.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The GoogleMaps widget is wrapped by Stack, since we will be adding some buttons over the map. Therefore, the zoom controls are also disabled since we won\u2019t be using that.<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">The above code should produce a result as shown below. You can interact with it as you normally would with Google Maps.<\/span><\/p>\n<p align=\"center\"><a href=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"304\" height=\"628\" src=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG1.png\" alt=\"\" class=\"wp-image-1568 alignnone size-medium\" style=\"margin-left: auto;margin-right: auto\" srcset=\"https:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG1.png 304w, https:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG1-145x300.png 145w\" sizes=\"(max-width: 304px) 100vw, 304px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">We can start working on the <a href=\"https:\/\/www.confianzit.com\/mobile-app-development\">app<\/a> and some of the features of the package. Basically, we will implement a route tracer where we will mock the movement of the device by generating random latitude and longitudes and then drawing a polyline following the route.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">We will first add our current location as a class variable.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\"> LatLng _currentLatLng = LatLng(35.22690877158998, -80.84422853576228);<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">Then we can create a function to change the camera position to a new location. This can be achieved by accessing the GoogleMapsController we had a reference to and using the animateCamera method in it which has to be provided with a CameraUpdate object initialized with the new CameraPosition.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">Future updateCameraLocation() async {\n    final GoogleMapController controller = await _controller.future;\n    final CameraPosition _newCameraPosition =\n        CameraPosition(target: _currentLatLng, zoom: 16);\n \n    controller.animateCamera(CameraUpdate.newCameraPosition(_newCameraPosition));\n  }\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">We can now create and wire up a button that starts creating mock locations. This is achieved by creating a repeating timer which will change the _currentLatLng with a new set of randomized latitude and longitude and trigger the updateCameraLocation function to reflect the change in the map.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">We will also create a couple of class variables. One is a boolean variable called isMoving which is initialized to false. This will be used to identify whether we are updating the location and hence start or stop it. The base logic for this is shown below. The other variable called randomMovementTimer is used to store reference to the timer to cancel it later on. The timer is created when we want to simulate random movement.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">ElevatedButton(\n  style: ElevatedButton.styleFrom(\n    primary: isMoving ? Colors.red : Colors.blue,\n  ),\n  child: Text(isMoving ? 'Stop' : 'Start'),\n  onPressed: () {\n    setState(() {\n      isMoving = !isMoving;\n    });\n \n    if (isMoving) {\n      randomMovementTimer =\n          Timer.periodic(Duration(seconds: 4), (timer) {\n        _currentLatLng = LatLng(\n            _currentLatLng.latitude + getRandomNumber(),\n            _currentLatLng.longitude + getRandomNumber());\n        updateCameraLocation();\n      });\n    } else {\n      randomMovementTimer?.cancel();\n    }\n  },\n),\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">Here the _currentLatLng is updated with a new LatLng object which increments its latitude and longitude by a random decimal number. This is calculated with the helper function getRandomNumber().<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">double getRandomNumber() {\n    final random = Random();\n    double number = random.nextDouble() \/ 1000;\n    return random.nextBool() ? number : 0 - number;\n}\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">That should wrap up our location mocking logic. If you click the start button now, the app should change locations every 4 seconds.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Adding a polyline (route trace)<\/b><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Now we can see how we can use the polylines available in the package to draw lines that trace the changes in the location.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">For this we will need to add the _polyline property to the GoogleMap widget. This will have to be initialized with a set of Polyline objects and each of these Polyline objects will be initialized with a list of LatLng points and identified by a PolylineId.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">So basically we will initialize a class variable of type Set&lt;Polyline&gt; with a single Polyline object with our initial coordinates. The ID of Polyline can simply be any unique string, here we will use the stringified version of our initial LatLng object. Furthermore, we will also add another variable called latLngList which tracks each location change so that we can get a continuous line when we create the polylines. This list will also be initialized with our initial coordinates.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">Set _polyline = {\n    Polyline(\n      polylineId: PolylineId(LatLng(35.22690877158998, -80.84422853576228).toString()),\n      points: [\n        LatLng(35.22690877158998, -80.84422853576228)\n      ],\nwidth: 2\n    )\n  };\n \nList latLngList = [LatLng(35.22690877158998, -80.84422853576228)];\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">The polyline property of the GoogleMap widget now needs to be set to the _polyline variable we defined.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">...\nGoogleMap(\n  mapType: MapType.normal,\n  initialCameraPosition: _initialCameraPosition,\n  polylines: _polyline,\n  onMapCreated: (GoogleMapController controller) {\n    _controller.complete(controller);\n  },\n  zoomControlsEnabled: false,\n),\n...\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">We can now change the updateCameraLocation function defined before to add a new polyline to our _polyline set. <\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">Future updateCameraLocation() async {\n    final GoogleMapController controller = await _controller.future;\n    latLngList.add(_currentLatLng);\n \n    setState(() {\n      _polyline.add(Polyline(\n          polylineId: PolylineId(_currentLatLng.toString()),\n          points: latLngList,\n          width: 2));\n    });\n \n    final CameraPosition _newCameraPosition =\n        CameraPosition(target: _currentLatLng, zoom: 16);\n \n    controller.animateCamera(CameraUpdate.newCameraPosition(_newCameraPosition));\n}\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">Note that we are wrapping the polyline addition within a setstate so as to reflect the updated UI (i.e. the line on the map).<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">This should wrap up our simple implementation of a route tracer. But let\u2019s try extending the app a bit more using some other APIs available in the package, perhaps placing markers on our path.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Adding markers<\/b><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Implementing markers also follows a very similar logic as creating polylines. It basically involves creating a set of Marker objects each with a unique MarkerId and a LatLng coordinate to display the marker.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">We will integrate the marker logic by adding another button which allows us to drop a marker at that point. And as for the marker ID, it would be the same as before (i.e. we will use a stringified version of the currentLatLng object). So as before we will add a private class variable to store the markers called _markers and assign it to the markers property of the GoogleMap widget.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">...\nGoogleMap(\n  mapType: MapType.normal,\n  initialCameraPosition: _initialCameraPosition,\n  polylines: _polyline,\n  markers: _markers,\n  onMapCreated: (GoogleMapController controller) {\n    _controller.complete(controller);\n  },\n  zoomControlsEnabled: false,\n),\n...\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; column_structure=&#8221;2_3,1_3&#8243; sticky_enabled=&#8221;0&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">Now we can write a function that will drop a marker at the currentLatLng by adding it to _markers.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">void _dropMarkerAtCurrentLocation() {\n    setState(() {\n      _markers.add(Marker(\n        markerId: MarkerId(_currentLatLng.toString()),\n        position: _currentLatLng,\n        icon: BitmapDescriptor.defaultMarker,\n      ));\n    });\n  }\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">Then we can create a button and wire up this function in the stack as shown.<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">ElevatedButton(\nonPressed: _dropMarkerAtCurrentLocation,\nchild: Text('Drop Marker'),\n)\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;]<\/p>\n<p><span style=\"font-weight: 400\">This should wrap our simple application. The final code for the entire implementation should look like this:<\/span><\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; text_text_color=&#8221;#000000&#8243; background_color=&#8221;#eff0f1&#8243; custom_margin=&#8221;|||60px|false|false&#8221; custom_padding=&#8221;3%|10%|2.5%|10%|false|false&#8221; border_width_top=&#8221;10px&#8221; border_color_top=&#8221;#2ea3f2&#8243;]<\/p>\n<pre class=\"java\" style=\"font-family: monospace\">import 'dart:async';\nimport 'dart:math';\n \nimport 'package:flutter\/material.dart';\nimport 'package:google_maps_flutter\/google_maps_flutter.dart';\n \nvoid main() =&gt; runApp(MyApp());\n \nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      title: 'Flutter Google Maps Demo',\n      home: MapPage(),\n    );\n  }\n}\n \nclass MapPage extends StatefulWidget {\n  @override\n  State createState() =&gt; MapPageState();\n}\n \nclass MapPageState extends State {\n  Completer _controller = Completer();\n  Timer? randomMovementTimer;\n  bool isMoving = false;\n \n  static final CameraPosition _initialCameraPosition = CameraPosition(\n    target: LatLng(35.22690877158998, -80.84422853576228),\n    zoom: 16,\n  );\n \n  LatLng _currentLatLng = LatLng(35.22690877158998, -80.84422853576228);\n  List latLngList = [LatLng(35.22690877158998, -80.84422853576228)];\n  Set _polyline = {\n    Polyline(\n        polylineId: PolylineId(\n            LatLng(35.22690877158998, -80.84422853576228).toString()),\n        points: [LatLng(35.22690877158998, -80.84422853576228)])\n  };\n  Set _markers = {};\n \n  @override\n  void initState() {\n    super.initState();\n  }\n \n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      body: Stack(\n        children: [\n          GoogleMap(\n            mapType: MapType.normal,\n            initialCameraPosition: _initialCameraPosition,\n            polylines: _polyline,\n            markers: _markers,\n            onMapCreated: (GoogleMapController controller) {\n              _controller.complete(controller);\n            },\n            zoomControlsEnabled: false,\n          ),\n          Positioned(\n            right: 20,\n            bottom: 20,\n            child: Column(\n              mainAxisAlignment: MainAxisAlignment.start,\n              crossAxisAlignment: CrossAxisAlignment.end,\n              children: [\n                ElevatedButton(\n                  style: ElevatedButton.styleFrom(\n                    primary: isMoving ? Colors.red : Colors.blue,\n                  ),\n                  child: Text(isMoving ? 'Stop' : 'Start'),\n                  onPressed: () {\n                    setState(() {\n                      isMoving = !isMoving;\n                    });\n \n                    if (isMoving) {\n                      randomMovementTimer =\n                          Timer.periodic(Duration(seconds: 4), (timer) {\n                        _currentLatLng = LatLng(\n                            _currentLatLng.latitude + getRandomNumber(),\n                            _currentLatLng.longitude + getRandomNumber());\n                        updateCameraLocation();\n                      });\n                    } else {\n                      randomMovementTimer?.cancel();\n                    }\n                  },\n                ),\n                ElevatedButton(\n                  onPressed: _dropMarkerAtCurrentLocation,\n                  child: Text('Drop Marker'),\n                )\n              ],\n            ),\n          ),\n        ],\n      ),\n    );\n  }\n \n  Future updateCameraLocation() async {\n    final GoogleMapController controller = await _controller.future;\n    latLngList.add(_currentLatLng);\n \n    setState(() {\n      _polyline.add(Polyline(\n          polylineId: PolylineId(_currentLatLng.toString()),\n          points: latLngList,\n          width: 2));\n    });\n \n    final CameraPosition _newCameraPosition =\n        CameraPosition(target: _currentLatLng, zoom: 16);\n \n    controller\n        .animateCamera(CameraUpdate.newCameraPosition(_newCameraPosition));\n  }\n \n  double getRandomNumber() {\n    final random = Random();\n    double number = random.nextDouble() \/ 1000;\n    return random.nextBool() ? number : 0 - number;\n  }\n \n  void _dropMarkerAtCurrentLocation() {\n    setState(() {\n      _markers.add(Marker(\n        markerId: MarkerId(_currentLatLng.toString()),\n        position: _currentLatLng,\n        icon: BitmapDescriptor.defaultMarker,\n      ));\n    });\n  }\n}\n<\/pre>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; column_structure=&#8221;2_3,1_3&#8243;][et_pb_column type=&#8221;2_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][et_pb_text _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;3px|||||&#8221;]<\/p>\n<p><span style=\"font-weight: 400;\">And our final <a href=\"https:\/\/www.confianzit.com\/mobile-app-development\">app<\/a> should look like this:<\/span><\/p>\n<p align=\"center\"><a href=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"299\" height=\"532\" src=\"http:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG2.png\" alt=\"\" class=\"wp-image-1566 alignnone size-medium\" style=\"margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG2.png 299w, https:\/\/www.confianzit.com\/cit-blog\/wp-content\/uploads\/2021\/06\/GMapsFlutter-IMG2-169x300.png 169w\" sizes=\"(max-width: 299px) 100vw, 299px\" \/><\/a><\/p>\n<p><b>Conclusion<\/b><\/p>\n<p><span style=\"font-weight: 400;\">We have now seen how we can use Google Maps and how relatively simple it is to integrate into an application and develop a UI if need be on top of it. A big question that might arise is the use of the current location of the device. While it is not directly possible within the application, there are still other packages which can provide that info such as the geolocator package or the location package and the values from that can be simply be used at the time of initialization of the map.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Currently the google_maps_flutter package is still not complete in the sense that some of the APIs such as showing heatmaps which are available on the web are not present here. Hopefully the package is still under active development and should eventually reach <a href=\"https:\/\/www.confianzit.com\/cit-blog\/flutter-paginated-lazy-loading-listview\/\">Flutter<\/a>.<\/span><\/p>\n<p>If you like to start your <a href=\"https:\/\/www.confianzit.com\/mobile-app-development\">Mobile App Development<\/a> project, <a href=\"https:\/\/www.confianzit.com\/hire-android-developer\">Hire Android<\/a> or <a href=\"https:\/\/www.confianzit.com\/hire-ios-developer\">iOS Developer<\/a> from Confianz Global INC.<\/p>\n<p>[\/et_pb_text][\/et_pb_column][et_pb_column type=&#8221;1_3&#8243; _builder_version=&#8221;4.9.4&#8243; _module_preset=&#8221;default&#8221;][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":11,"featured_media":1572,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[79,80,5,78,8],"tags":[161,188,93,183],"_links":{"self":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts\/1561"}],"collection":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/comments?post=1561"}],"version-history":[{"count":15,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts\/1561\/revisions"}],"predecessor-version":[{"id":1976,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/posts\/1561\/revisions\/1976"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/media\/1572"}],"wp:attachment":[{"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/media?parent=1561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/categories?post=1561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.confianzit.com\/cit-blog\/wp-json\/wp\/v2\/tags?post=1561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}