Skip to content

Instantly share code, notes, and snippets.

@fselcukcan
Last active June 16, 2025 12:58
Show Gist options
  • Save fselcukcan/b5de1aaf88fddc197005c50ea80bb9b4 to your computer and use it in GitHub Desktop.
Save fselcukcan/b5de1aaf88fddc197005c50ea80bb9b4 to your computer and use it in GitHub Desktop.
Map with a current location and current heading
(ns acme.main
(:require ["dart:async" :as da]
["package:flutter/material.dart" :as m]
[cljd.flutter :as f]
["package:flutter_map/flutter_map.dart" :as fm]
["package:flutter_map_location_marker/flutter_map_location_marker.dart" :as fmlm]
["package:latlong2/latlong.dart" :as ll]
#_["package:geolocator/geolocator.dart" :as geo]
#_["package:flutter_rotation_sensor/flutter_rotation_sensor.dart" :as rs]
["package:url_launcher/url_launcher.dart" :as ul]))
; Position and Heading Streams
;; cljd port of flutter_map_location_marker default_stream_example.dart:
;; https://github.com/tlserver/flutter_map_location_marker/blob/main/example/lib/page/default_stream_example.dart
(defn map-view []
(f/widget
:let [factory (fmlm/LocationMarkerDataStreamFactory)
align-position-stream-controller (da/StreamController)
apou (atom fmlm/AlignOnUpdate.always)
adou (atom fmlm/AlignOnUpdate.always)]
:watch [position-stream (.asBroadcastStream (.fromGeolocatorPositionStream factory))
heading-stream (.asBroadcastStream (.fromRotationSensorHeadingStream factory))
align-position-stream (.-stream align-position-stream-controller)
align-position-on-update apou
align-direction-on-update adou]
(fm/FlutterMap
.options (fm/MapOptions
.initialZoom 19
; Stop aligning the location marker to the center of the map widget
; if user interacted with the map.
.onPositionChanged (fn [fmlm/MapCamera hasGesture]
(if (and hasGesture (not= align-position-on-update fmlm/AlignOnUpdate.never)) ; maybe also check align-direction-on-update
(do
(reset! apou fmlm/AlignOnUpdate.never)
; maybe also
(reset! adou fmlm/AlignOnUpdate.never) ))))
.children [(fm/TileLayer
.urlTemplate "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
.userAgentPackageName "com.yilki.app")
(fmlm/CurrentLocationLayer
.positionStream position-stream
.headingStream heading-stream
.alignPositionStream align-position-stream
.alignPositionOnUpdate align-position-on-update
.alignDirectionOnUpdate align-direction-on-update
.style (fmlm/LocationMarkerStyle
.marker (fmlm/DefaultLocationMarker
.child (m/Icon m/Icons.navigation .color m/Colors.white))
.markerSize (m/Size 40 40)
.markerDirection fmlm/MarkerDirection.heading))
(m/Align
.alignment m/Alignment.bottomRight
.child (m/Padding
.padding (m/EdgeInsets.all 20.0)
.child (m/FloatingActionButton
.onPressed (fn []
; Align the location marker to the center of the map widget
; on location update until user interact with the map.
(reset! apou fmlm/AlignOnUpdate.always)
;maybe also
(reset! adou fmlm/AlignOnUpdate.always)
;maybe also set the device location marker location to the last known location
; Align the location marker to the center of the map widget
; and zoom the map to level 18.
(.add align-position-stream-controller 18))
.child (m/Icon m/Icons.my_location .color m/Colors.white))))
(fm/RichAttributionWidget
.attributions [(fm/TextSourceAttribution
"OpenStreetMap contributors"
#_#_.onTap (fn [] (ul/launchUrl (Uri.parse "https://openstreetmap.org/copyright"))))])])))
(defn main []
(f/run
(m/MaterialApp
.title "Flutter Loc Marker with streams"
.theme (m/ThemeData .primarySwatch m.Colors/pink))
.home
(m/Scaffold
.appBar (m/AppBar
.title (m/Text "Flutter Loc Marker with streams")))
.body
(m/Center
.child (map-view))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment