evopimp / easy_maps_plus

Draw routes and calculate distances easily with Google Maps in Flutter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EasyMapPlus

EasyMapPlus is a Flutter package that provides a simple and easy-to-use widget to display driving directions on a Google Map. With EasyMap, you can easily plot polylines between multiple coordinates and optionally display markers for the origin and destination points.

Installation

To use EasyMapPlus, add the package to your pubspec.yaml file:

dependencies:
  easy_map_plus: 0.1.6

Then, run flutter pub get to fetch the package.

Usage

To use the EasyMap widget, simply import the package and include it in your Flutter app. Here's an example of how to use it:

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

void main() {
  // Initialize the EasyMap widget with your Location IQ API key
  EasyMap.init(API_KEY);

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('EasyMapPlus'),
        ),
        body: EasyMap(
          coordinates: [
            LatLng(37.7749, -122.4194), // Origin
            LatLng(34.0522, -118.2437), // Destination
            // Add more waypoints as needed
          ],
          onMapCreated: (GoogleMapController controller) {
            // Map initialization callback
          },
          destinationIcon: BitmapDescriptor.hueBlue, // default BitmapDescriptor.hueRed
          polylinesColor: Colors.blue,
          mapType: MapType.normal,
          showMarkers: true,
          initialCameraPosition: CameraPosition(
            target: LatLng(37.7749, -122.4194),
            zoom: 15,
          ), // Defaults to the first coordinate in the `coordinates` list if not provided
          cameraTargetBounds: const CameraTargetBounds(null), 

        ),
      ),
    );
  }
}

Widget Properties

The EasyMap widget supports the following properties:

  • apiKey (required): Your Location IQ API key. You can obtain one from the official website.
  • coordinates (required): A list of LatLng representing the waypoints for the driving directions. The first and last coordinates will be considered as the origin and destination, respectively.
  • onMapCreated (required): A callback function that will be called when the GoogleMapController is ready to be used.
  • polylinesColor (required): The color of the polylines that will be drawn on the map.
  • destinationIcon: The hue of the color of the destination marker.
  • originIcon: The hue of the color of the origin marker.
  • initialCameraPosition: The initial camera position for the map. If not provided, it will default to the first coordinate in the coordinates list with a zoom level of 15.
  • mapType: The type of map to display (e.g., normal, satellite, terrain, etc.). Defaults to MapType.normal.
  • showMarkers: A boolean indicating whether to display markers for the origin and destination points. Defaults to true.

Additional Information

  • The DrivingDirections class is used internally to fetch driving directions from Google Maps. It decodes the response and extracts the necessary coordinates for drawing polylines on the map.

  • await EasyMap.findPlaces('Paris');

    This method can be used to find places using the Location IQ API. It returns a list of ForwardGeo objects that contain informations about found places.

  • await EasyMap.findInfos(LatLng(37.7749, -122.4194));

    This method can be used to find an address using the Location IQ API. It returns a ReverseGeo object that contains informations about the address.

Contributing

If you find a bug or have a feature request, please file an issue on GitHub or submit a pull request. All contributions are welcome!

Happy mapping!

About

Draw routes and calculate distances easily with Google Maps in Flutter.

License:MIT License


Languages

Language:C++ 34.9%Language:CMake 28.7%Language:Dart 24.3%Language:HTML 5.7%Language:Swift 3.7%Language:C 2.2%Language:Kotlin 0.4%Language:Objective-C 0.1%