How to add live location tracking in flutter_map? - flutter

How to integrate live tracking with flutter_map. Does anyone know which library is integrated into it? or How to implement it?

In order to do this, we need to understand what live location tracking is. Mainly it consists of these:
The location being broadcasted (the one being tracked) => 1st party.
The listener for these location updates (observer) => 2nd party.
A place to store these changes, which acts as a middle ground between the two parties. This is your database. Could be FireStore, or a traditional database.
Your 1st party will have to be aware or location changes, and when it's coordinates change, it will post the new coordinates to your database. This can be done using your location package, either Location or Geolocator or other dependancies. You listen to onLocationChanged.
Your 2nd party will be monitoring your database, for any new coordinates being posted. Ideally, it would be by utilizing a streambuilder in Flutter, which listen to a stream of events coming from your database via your server, or more practically, via FirebaseFirestore streams.
When your 2nd party receives these new coordinates, it will updated the map with the newly received data. You implement this by using two things:
Add a marker to the map, the marker takes a required LatLng argument. This is the LatLng you just received.
You also have to animate the camera, to point at the newly received LatLng.
Now, you have 1st party uploading it's data whenever location changes, and 2nd party getting the data as soon as it is being uploaded, and you have live tracking. Implementing it isn't as hard as you imagine.
Use Flutter google maps.
Enable google maps API in google cloud console for your platform(s), Android, iOS, JavaScript if you want web.
Install your location dependency.
Update your database with the new coords when they change.
Build your map widget on your 2nd party's device, as per the documentation, which is crystal clear,and put it in a streambuilder.
Update this map with the new coords.
You get a location tracking system.

It uses user_location_plugin
I don't think you want to implement it yourself.

Related

Determine source of Database Event in Firebase RealTime Database and Flutter

I have a Flutter app using Firebase Realtime database. I have created subscriptions to add, change, and delete for a node.
I would like to determine if the DatabaseEvent received for these subscriptions was generated by the local application, or by something else (for example, a direct edit using the Firebase Console.)
I know I could probably store some information when I issue the database add, change or delete, and then when I receive the event compare to see if the same item referenced, but I was hoping to see if there was some information in the Event itself (or somewhere else) that would tell me this.
Anyone have an idea?
I have examined the DatabaseEvent object returned when the subscriptions fire, but I don't see any information that could help.
firebaser here
There is nothing built in for this in the Firebase Realtime Database SDK or in any of its other APIs. If you want to know the source of the data, you'll have to track it yourself.
One of our early demo apps for a shared whiteboard held a list of the push keys for all its pending writes, so that it could filter those in its listener (as it had already drawn the local strokes before even sending them to the database). But there are many other valid approaches for this too.

Google map in flutter application

Can we implement google maps in a flutter application which runs once and fetches route from location1 to location2 and then we can move over the route without placing any new request to google API console?
Like, for the hikers and travelers who is supposed to be in a part where they may not have internet access then can user offline routes saved on device.
Thanks
I have tried google console APIs but it requires timely requests and costs a lot.
In my case, I use Flutter Map with Google Map Tile layer. When performing routing, API server sends me a list of Coordinates that make up a path from start to end. Then I just add them to Polyline layer to display on the map.
yes, you can do it. You have to hit the direction API to get the direction from point A to Point B. In JSON response you will get all the required data, like polyline points, steps, routes, and Lat, Lng. Save the polyLine points and draw polylines on GoogleMaps. And when you move, simply get your latLng from GPS using a geolocator or Location package and set a listener on it for every movement. And now it will work without the internet. But for another request, you will need internet.

Flutter – question about architecture, providers and fetching data from server

I am a rather fresh Flutter programmer so please excuse any flaws in the questions below…
I am struggling with a structural/ architecture dilemma. Here is the background:
App rationale:
my app allows its users to check little jobs available in their area and if they find time and are in a proper location to execute the job for a remuneration,
the app uses standard REST API (not Firebase) so that the server cannot be relied on sending status change notifications to trigger re-fetching of data,
the critical elements are (1) up-to date list of jobs for a given address - other user may have already taken on a job in an address (timed refresh of list e.g. every 5 mins), and (2) the app needs to keep track of the user’s location and accordingly ask the server for jobs if the user relocates by more than 2km in less than the refresh time,
The challenge:
I guess that on the basic level the app should have the following providers: (1) auth – providing the authToken, (2) geolocation – regularly checking user’s location, (3) jobList - for particular location (fetches high level job descriptions and addresses(, (4) jobDetails – fetches exact instructions for carrying a particular job,
as you can see: (2) geolocation and (3) jobList – need to refresh programmatically (at interval or on some change of geolocation), while (1) auth, (4) jobDetails are triggered by the user.
The Big Question ;) is … what is the proper architecture for the above type of app? More specifically:
should I use services for connecting to the server API and these would in turn be used by the providers?
how to ensure programmatic refetch of jobList on timer and relocation event from geolocation?
how to continually listen to location changes to detect a relocation but not overwhelming the app with processing?
should I store the (quickly outdating) jobLIst data just in its object class or should I use settings provider or a local db or maybe there is an easy way of storing the latest JSON response not to have to build the settings provider or db mapping?
in all my call to Auth api I need to provide the deviceId - how to make it available accross the app - this is pretty static but is needed in authentication so should checking it be a part of the auth provider?
If you could comment on the above or suggest a source of relevant examples I would be really grateful.
Thanks and cheers!
Here are my thoughts:
how to continually listen to location changes to detect a relocation but not overwhelming the app with processing?
You can rely on third party to do this for you. Such as: geolocator. With this, you can specify the amount of distance the user must have moved before the package notifies you of the change in user location.
should I store the (quickly outdating) jobLIst data just in its object class or ...
Since it is likely for a job listing app to use this data often and in various places, I would prefer to use db. It would be helpful in the long run too, if you plan to have some sort of analytics done on the mobile end or to gather any insights.
in all my call to Auth api I need to provide the deviceId - how to make it available accross the app ...
When you app is initialized, you could fetch the deviceID and store it in shared_preferences. Then in auth api, you could just retrieve it before making the API call.
should I use services for connecting to the server API and these would in turn be used by the providers?
As for geo location, geolocator can update you about the change in location and you could make an API call based on that.
However, if you plan to have a timer based approach to refresh your job listing, then you must realize that your users are likely to face issues arising from your inconsistent data. If you have plans to tackle it, then this implementation here might help. But I strongly feel that server supporting push notifications or maybe a web socket approach would be ideal here.

Map Widgets recibing data from different Context Brokers and the workspace tabs

In my Wire Cloud mashup I want to use two different maps, each maps get data from a different operator and each operator consult a different instance of ORION context broker.
When I put this two operators and the two maps in differents workspaces, this components work fine. If I put all this components in the same mashup and the same tab, also works fine. In this two cases, I recieve the data from the context broker, the operator send this data adapted for the map and this one represent the data perfectly.
My problem occurs when I put these operators and maps in the same mashup but in different tab each one. In this case i always obtain the following error:
Exception catched while processing an event that reached the "notiCAM" input endpoint fdcae15cbdc8.js:775
log fdcae15cbdc8.js:775
propagate fdcae15cbdc8.js:853
_notifyLoaded fdcae15cbdc8.js:744
After many hours trying to fix this case, I can´t find why this maps and operators does not work in this third case, is someone in this same situation? which solution worked in your case?
thanks
P.D: For my maps im using google maps API
I'm assuming you're not using the "Map Viewer" widget available on the FI-LAB store.
The problem seems to be related to the way your map widget handles incoming events. Take into account that:
Widgets are loaded when the tab where they are located is displayed or when a first event arrives on any of their input endpoints
Any event arriving on an input endpoint of an unloaded widget/operator gets queued until that widget/operator is fully loaded
WireCloud assumes widget/operators are fully loaded by capturing the "load" event of their iframe
The Google Map API is usually loaded asynchronously, making your widget unable to manage those incoming events until that API get ready (some time after the load event).
Currently, the only viable solution is to buffer events arriving on the "notiCAM" endpoint after the load event but before the google maps api is loaded, handling them just when that api notifies you that it's ready.

Changing a UITableViewController dynamically via location

I am in the process of building an app, for the record I am using the code from the ECSlidingView controller. I would like for my app to use the GPS to pull data from my web interface letting the user know that they can do certain things at a given location. So for example, I have a user go to a store and lets say I want them to make a payment at that location, it will given them that option. Or if the store doesn't offer payment through the app, I disable that. What would be a good way to go about this?
You could try using CoreLocation but you might have trouble getting accurate location inside (it will most probably use wifi or cellular info so the accuracy might not be what you expect). Then, when you get the location, issue a request to your service passing latitude and longiude you receive from CoreLocation. There, you should search by location to retrieve possible matches - consider returning muliple store infos for nearby stores due to the accuracy issues.