Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

googlemapswidget for flutter

a flutter package which can be used to make polylines(route) from a source to a destination, and also handle a driver’s realtime location (if any) on the map.

a widget for flutter developers to easily integrate google maps in their apps. it can be used to make polylines from a source to a destination, and also handle a driver’s realtime location (if any) on the map.

features

  • make polylines (route) between two locations by providing the latitude and longitude for both the locations.
  • the route is customizable in terms of color and width.
  • the plugin also offers realtime location tracking for a driver(if any) and shows a marker on the map which updates everytimes the driver’s location changes.
  • all the markers are customizable.
  • ontap callbacks are implemented for all the markers and their info windows to easily handle user interaction.
  • almost all the parameters defined in google_maps_flutter for the googlemap widget can be passed as arguments to the widget.

screenshots

      

getting started

  • get an api key at https://cloud.google.com/maps-platform/.
  • enable google map sdk for each platform.
    • go to google developers console.
    • choose the project that you want to enable google maps on.
    • select the navigation menu and then select “google maps”.
    • select “apis” under the google maps menu.
    • to enable google maps for android, select “maps sdk for android” in the “additional apis” section, then select “enable”.
    • to enable google maps for ios, select “maps sdk for ios” in the “additional apis” section, then select “enable”.
    • to enable directions api, select “directions api” in the “additional apis” section, then select “enable”.
    • make sure the apis you enabled are under the “enabled apis” section.

for more details, see getting started with google maps platform.

android

specify your api key in the application manifest android/app/src/main/androidmanifest.xml:

<manifest ...
  <application ...
    <meta-data android:name="com.google.android.geo.api_key"
               android:value="your key here"/>

ios

specify your api key in the application delegate ios/runner/appdelegate.m:

#include "appdelegate.h"
#include "generatedpluginregistrant.h"
#import "googlemaps/googlemaps.h"

@implementation appdelegate

- (bool)application:(uiapplication *)application
    didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {
  [gmsservices provideapikey:@"your key here"];
  [generatedpluginregistrant registerwithregistry:self];
  return [super application:application didfinishlaunchingwithoptions:launchoptions];
}
@end

or in your swift code, specify your api key in the application delegate ios/runner/appdelegate.swift:

import uikit
import flutter
import googlemaps

@uiapplicationmain
@objc class appdelegate: flutterappdelegate {
  override func application(
    _ application: uiapplication,
    didfinishlaunchingwithoptions launchoptions: [uiapplication.launchoptionskey: any]?
  ) -> bool {
    gmsservices.provideapikey("your key here")
    generatedpluginregistrant.register(with: self)
    return super.application(application, didfinishlaunchingwithoptions: launchoptions)
  }
}

web

modify web/index.html

get an api key for google maps javascript api. get started here.
modify the <head> tag of your web/index.html to load the google maps javascript api, like so:

<head>

  <!-- // other stuff -->

  <script src="https://maps.googleapis.com/maps/api/js?key=your_key_here"></script>
</head>

usage

to use this plugin, add google_maps_widget as a dependency in your pubspec.yaml file.

  dependencies:
    flutter:
      sdk: flutter
    google_maps_widget:

first and foremost, import the widget.

import 'package:google_maps_widget/google_maps_widget.dart';

you can now add a googlemapswidget widget to your widget tree and pass all the required parameters to get started.
this widget will create a route between the source and the destination latlng’s provided.

googlemapswidget(
    apikey: "your key here",
    sourcelatlng: latlng(40.484000837597925, -3.369978368282318),
    destinationlatlng: latlng(40.48017307700204, -3.3618026599287987),
),

sample usage

import 'package:flutter/material.dart';
import 'package:google_maps_widget/google_maps_widget.dart';

void main() {
  runapp(myapp());
}

class myapp extends statelesswidget {
  @override
  widget build(buildcontext context) {
    return materialapp(
      home: safearea(
        child: scaffold(
          body: googlemapswidget(
            apikey: "your key here",
            sourcelatlng: latlng(40.484000837597925, -3.369978368282318),
            destinationlatlng: latlng(40.48017307700204, -3.3618026599287987),

            ///////////////////////////////////////////////////////
            //////////////    optional parameters    //////////////
            ///////////////////////////////////////////////////////

            routewidth: 2,
            sourcemarkericoninfo: markericoninfo(
              assetpath: "assets/images/house-marker-icon.png",
            ),
            destinationmarkericoninfo: markericoninfo(
              assetpath: "assets/images/restaurant-marker-icon.png",
            ),
            drivermarkericoninfo: markericoninfo(
              assetpath: "assets/images/driver-marker-icon.png",
              assetmarkersize: size.square(125),
            ),
            // mock stream
            drivercoordinatesstream: stream.periodic(
              duration(milliseconds: 500),
              (i) => latlng(
                40.47747872288886 + i / 10000,
                -3.368043154478073 - i / 10000,
              ),
            ),
            sourcename: "this is source name",
            drivername: "alex",
            ontapdrivermarker: (currentlocation) {
              print("driver is currently at $currentlocation");
            },
            totaltimecallback: (time) => print(time),
            totaldistancecallback: (distance) => print(distance),

            /// and a lot more...
          ),
        ),
      ),
    );
  }
}

see the example directory for a complete sample app.


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.