Hello, I'm new to both programming and Flutter but I'm starting to
get my head around it. I am trying to put together an app that combines
user and location information via Firebase so that I can show multiple
user locations on a map. What I need help with and would like to do is
write the Firebase UID and user location to the same Firestore document
via a Typescript cloud function.
I've been working with
this
flutter Firebase background location plugin for several months and have figured
out a lot about how it works. Concurrently I've been trying multiple
Firebase Auth templates and have learned a fair amount about what API
options are available. Most importantly I understand that the UID is the
key value to identify my users.
I've also
learned a fair amount about Firebase cloud functions and how to write
specific data to a Firestore collection. I've learned how to write the
user information and UID to a collection with a Javascript cloud
function and I've also learned how to write the location information
(lat, lng, etc...) to a collection via a Typescript cloud function.
My
working Typescript is below, it has the location data I need. Can I
modify the Typescript to include information such as UID or perhaps
email address sourced from user data stored in Firebase? Thanks for
reading and for any suggestions on how to proceed. Nathan
import * as functions from 'firebase-functions';
exports.createLocation = functions.firestore
.document('locations/{locationId}')
.onCreate((snap, context) => {
const record = snap.data();
const location = record.location;
console.log('[data] - ', record);
return snap.ref.set({
uuid: location.uuid,
timestamp: location.timestamp,
is_moving: location.is_moving,
latitude: location.coords.latitude,
longitude: location.coords.longitude,
speed: location.coords.speed,
heading: location.coords.heading,
altitude: location.coords.altitude,
event: location.event,
battery_is_charging: location.battery.is_charging,
battery_level: location.battery.level,
activity_type: location.activity.type,
activity_confidence: location.activity.confidence,
extras: location.extras,
});
});