Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello sir thank you for your tutorial ,but can you help me how can i change location change state with web socket that will update location #8

Open
johnyenatu opened this issue Dec 2, 2020 · 2 comments

Comments

@johnyenatu
Copy link

No description provided.

@romanejaquez
Copy link
Owner

Hi @johnyenatu the best way to update the location change is using of course the location.onLocationChanged().listen, then inside the callback, you update the location.

location.onLocationChanged().listen((LocationData cLoc) {
// change here the location
});

If you want to implement it using web sockets (u mean via Firebase using the Real-Time Database?) i'd actually push the location changed inside that same method, send it up to Firebase to a collection that all users are reading:

location.onLocationChanged().listen((LocationData cLoc) {
// push the cLoc to firebase.
// can't remember the syntax now, but something like
firebase.collections('locationCollection').document('locUpdate').add(cLoc) // which should have lat and long
});

Then, on the other end of the communication, on the side of the user that will be looking at the changes moving, just listen for the changes in that collection document locUpdate, sort of like this:

var snapshots = _firestore
.collection('locationCollection')
.getDocuments();

await snapshots.forEach((document) async {
// update the map pin location with the information from the user who changed it
mapPin.setLocation(document.lat, document.long);
});

None of the syntax is correct above, is just so you can get the idea. I haven't implemented it yet, but that's how I'd do it if using Firebase Real-time DB for example.

@johnyenatu
Copy link
Author

Hi @johnyenatu the best way to update the location change is using of course the location.onLocationChanged().listen, then inside the callback, you update the location.

location.onLocationChanged().listen((LocationData cLoc) {
// change here the location
});

If you want to implement it using web sockets (u mean via Firebase using the Real-Time Database?) i'd actually push the location changed inside that same method, send it up to Firebase to a collection that all users are reading:

location.onLocationChanged().listen((LocationData cLoc) {
// push the cLoc to firebase.
// can't remember the syntax now, but something like
firebase.collections('locationCollection').document('locUpdate').add(cLoc) // which should have lat and long
});

Then, on the other end of the communication, on the side of the user that will be looking at the changes moving, just listen for the changes in that collection document locUpdate, sort of like this:

var snapshots = _firestore
.collection('locationCollection')
.getDocuments();

await snapshots.forEach((document) async {
// update the map pin location with the information from the user who changed it
mapPin.setLocation(document.lat, document.long);
});

None of the syntax is correct above, is just so you can get the idea. I haven't implemented it yet, but that's how I'd do it if using Firebase Real-time DB for example.

thank you sir for your response it descriptive ,but can you elaborate on live tracking from firebase or other side where should I change or call backend to move marker .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants