map_navigation_utils 0.0.3 copy "map_navigation_utils: ^0.0.3" to clipboard
map_navigation_utils: ^0.0.3 copied to clipboard

A Flutter package that provides smooth Google Maps marker animation, polyline decoding, and distance/bearing calculation utilities for navigation apps.

map_navigation_utils #

A powerful Flutter package that helps you easily work with Google Maps by providing smooth marker animations, polyline decoding, and distance/bearing calculations.

πŸš€ Features #

Pub Version Likes Points Popularity

  • βœ” Smooth marker animation
  • βœ” Google-style encoded polyline decoder
  • βœ” Distance calculator (Haversine formula)
  • βœ” Bearing angle calculator
  • βœ” Lightweight & easy to use

πŸ“¦ Installation #

Add this to your pubspec.yaml:

dependencies:
  map_navigation_utils: ^1.0.0

Import the package:

import 'package:map_navigation_utils/map_navigation_utils.dart';

🎯 Usage Examples #

πŸ”Ή 1. Decode Polyline #

final points = PolylineDecoder.decode(encodedString);

πŸ”Ή 2. Calculate Distance Between Coordinates #

final distance = GeoUtils.calculateDistance(
  lat1,
  lon1,
  lat2,
  lon2,
);

πŸ”Ή 3. Calculate Bearing #

final bearing = GeoUtils.calculateBearing(
  lat1,
  lon1,
  lat2,
  lon2,
);

πŸ”Ή 4. Smooth Marker Animation #

MarkerAnimator.smoothMove(
  controller: mapController,
  markerId: MarkerId('bus'),
  from: oldLatLng,
  to: newLatLng,
);

πŸ“‚ Example Project #

A full working demo is available inside:

example/lib/main.dart

πŸ—Ί Roadmap #

  • Add route snapping
  • Multi-marker smooth animation
  • Route prediction & ETA utilities

πŸ“˜ Advanced Usage #

πŸ”₯ Smooth Marker Animation with Duration #

await MarkerAnimator.smoothMove(
  controller: mapController,
  markerId: const MarkerId('vehicle'),
  from: oldPosition,
  to: newPosition,
  duration: const Duration(seconds: 2),
);

🧭 Recalculate Polyline + Bearing #

final decoded = PolylineDecoder.decode(encodedPolyline);
final bearing = GeoUtils.calculateBearing(
  decoded.first.latitude,
  decoded.first.longitude,
  decoded.last.latitude,
  decoded.last.longitude,
);

πŸ“Έ Screenshots (Add your images here) #

Place your package screenshots in:

/example/assets/

And reference them like:

![Demo](example/assets/demo.png)

πŸ›  Example (Full Code Snippet) #

Use this snippet in your example/lib/main.dart:

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:map_navigation_utils/map_navigation_utils.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MapExample(),
    );
  }
}

class MapExample extends StatefulWidget {
  const MapExample({super.key});

  @override
  State<MapExample> createState() => _MapExampleState();
}

class _MapExampleState extends State<MapExample> {
  GoogleMapController? mapController;
  LatLng from = const LatLng(26.9124, 75.7873);
  LatLng to = const LatLng(26.9154, 75.7893);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Map Utils Example')),
      body: GoogleMap(
        initialCameraPosition: CameraPosition(target: from, zoom: 14),
        onMapCreated: (controller) => mapController = controller,
        markers: {
          Marker(
            markerId: const MarkerId('bus'),
            position: from,
          ),
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          await MarkerAnimator.smoothMove(
            controller: mapController!,
            markerId: const MarkerId('bus'),
            from: from,
            to: to,
          );
          setState(() => from = to);
        },
        child: const Icon(Icons.navigation),
      ),
    );
  }
}

πŸ“„ License #

This package is available under the MIT License.


❀️ Contribute #

Pull requests and feature suggestions are welcome!

2
likes
140
points
10
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that provides smooth Google Maps marker animation, polyline decoding, and distance/bearing calculation utilities for navigation apps.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, google_maps_flutter

More

Packages that depend on map_navigation_utils