GPS - subscribe to continuous updates

Actions & Logic

Can someone point me to some code to subscribe to continuous GPS updates?

Currently I am getting a position via a custom function every few seconds, but it is quite laggy. It does work, but I suspect it is far from the best way to do it.

Serge Middendorf mentioned the link below, and I can see that there is an option to subscribe to updates. I would also want to return these updates to the flow and a page variable.

Basically its a distance countdown as you approach a location. I want it to be as smooth as possible.

Any assistance gratefully received.

https://pub.dev/packages/geolocator

What have you tried so far?

Not sure where to start.

This is my current custom function;

// Automatic FlutterFlow imports import '/backend/backend.dart'; import '/actions/actions.dart' as action_blocks; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/actions/index.dart'; // Imports other custom actions import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom action code // DO NOT REMOVE OR MODIFY THE CODE ABOVE! import 'package:geolocator/geolocator.dart'; Future<List<double>> getPosition() async { // get current location and return latitude and longitude as doubles // Use the geolocator package to get the current position Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); // Extract the latitude and longitude from the position object double latitude = position.latitude; double longitude = position.longitude; // Return the latitude and longitude as a list of doubles return [latitude, longitude]; }

Did you check FlutterFlow's Documentation for this topic?
No
2
6 replies