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.8
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 ofLatLng
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 thecoordinates
list with a zoom level of 15.mapType
: The type of map to display (e.g., normal, satellite, terrain, etc.). Defaults toMapType.normal
.showMarkers
: A boolean indicating whether to display markers for the origin and destination points. Defaults totrue
.
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!