Udemy

Calculating Estimated Ride Fares using Distance and Duration

A free video tutorial from Ufinix Academy
Learn programming and app development
Rating: 4.3 out of 5Instructor rating
4 courses
8,185 students
Calculating Estimated Ride Fares using Distance and Duration

Learn more from the full course

Xamarin Android Uber Clone App with C# and Firebase

Learn advanced Xamarin Android concepts by building a fully complete and functional Uber Clone app using Firebase

15:26:55 of on-demand video • Updated July 2020

Learn to build complete Uber Clone apps (driver and passenger) with C#, Xamarin and Firebase
Learn to create, remove, update and delete records in Firebase Database
Save and handle data locally using Shared Preferences
Learn how to use Google Location and Map services in your Apps
Learn to find direction from one point to the other with Google Direction Api
Learn to find place address with Location Coordinates using Google Geocoding API
Learn advanced usage of C# Lambda Expressions
Learn advanced usage and creation of custom C# Event handlers
Learn to create and design beautiful User Interfaces
Understand how to create Local Notifications using Android Notification Manager
Learn to make asynchronous WebCallls using Rest Api
Learn to initiate a phone call from your app using Native Intents
English [Auto]
Hello. So welcome to this class. So in this class we're going to be looking at how to estimate defense for our tree. As you can see the tree from peak obligation to our destination will cost us several hundred sixty to seven inches or less. So I just want to say that this just estimates OK and the duration for our trip is estimated to be around one hour for two minutes. So we are going to be looking at how to get these values. All right. So this is actually real value. And this is based on our estimate. OK. So before we continue I want to give us some highlights on how to calculate actual fares. Right. So there is something called base fare the best fare is about equal amount. That means we charge for each trip. This chart also applies when a rider Kansas trip after the driver has right. That is the base fare. And also we have the time factor the time fare is an amount charge for every minute spent on the trip. And the last one is the distance for the distance where it is an amount charge for every kilometer on the trip. And when you sum this up all together it's in our form our total fares. All right. So this is actually the process you're going to be following in this class. So without much ado let's get right into it. So the first thing we need to do is to give the distance from our pickup location to our destination. All right. We to also get the duration for the trip. So to do that we need to go to our map function helper. All right. So good enough our direction API calls with this information inside of it. All right. So we are actually going to just go ahead and grab them. OK. So to do this we need to define some global variables that we can assess from outside this class. All right. So I'm going to go to the top and I'm going to say public double distance OK. So again I'm going to say public double duration I'm going to say public string distance string and probably string duration string came so I'm going to assign values to the variables Joyce created so I'm going to say duration will be equal to direction. Data rounds got legs the duration dot value. So this would actually give us the duration of the trip in milliseconds. All right. So the next one is distance the traction data the Ground Zero the legs the distance the value. OK. So the next is our duration stream. Right. The test. So this will actually give us a duration in test. OK. So you're going to spend one hour 20 minutes he's going to return one hour 20 minutes four hours. All right. So we're going to do the same for our distance stream. So he's going to return OK so we d strongly. So that's corrected okay distant stream will be opposed to direction. Data. Droughts 0 demands zero dot distance tests. OK so we are doing hardness and we need to do is to define a new method. Now estimate our phase. All right. So I'm going to say. Public void estimates phase. OK. So like I said we're going to copy the best format of calculating or estimating fares. So we need to get the distance festival. So to calculate the distance fare we need our distance. This is in meters so we need to combat it two kilometers FERRIS Right. So I'm going to say double kilometers equal to distance over 1000. This would convert our distance to kilometers right. And so to convert seconds to minutes which say double means the call to duration over 60. So this you convert so d you convert our duration in two minutes. Right. So before that we need to know the amounts are going to be charging as our base fare time fair and distance. So let's just go ahead and say double bass fare. We just said this to be 20 dollars. Just go ahead and said this 220 dollars USD and distance fare will be equal to. So we are going to be charging five bucks by these standards. All right. So like I said guys these are just intuitive values. So there are different ways you could go about to try to get it even be bringing new values from the database. But these I just tentative values for the purpose of this class alone array. These are not industry standards at all. OK. So our tame fare will be equal to let's say 80 bucks mean minute so we're just gonna go ahead and what's apply this by how I distance fare and we multiply these by our time frame. All right. So the amount sodium mountain will be so a distance fare which is in. So I can just go ahead and put it this way so our distance fares floors our time fares plus our base fare will give voice to an amount. OK. So to ensure we don't have you know decimal places you can just go ahead and round these down. All right. So many say double fares the quarter meant dance floor bracket amount over 10. What's the play by 10 so it is you always give voice I need to go find your whole number. So let's say we have a hundred and sixty point three dollars we're just around in doubt two hundred and sixty dollars. Well you have a hundred and sixty point seven dollars we're just around it too. We also ninety three hundred and sixty dollars. All right. Next thing we need to do is to return these value and return fares. So in that case we'll make this a public double. All right. So everything checks out. So now we need to go back to our main activity so that we can get these values from there and set it to our view. All right. So we need to get a reference to the tells you that displays our price estimates and our duration estimate. All right. So when you say it as view GST fair a to tells view rocket find you buy a D. Now Eydie don't trip estimates fast GST. I'm going to say this with you GST time gonna be a quote to test new markets find the Dubai I.D. market resource the IDA new cheap time test. OK so now we have these references we need to get the values of our estimates fair and our estimated time of arrival as well. So if that is method has been called because these really grab the values of our distance and our duration. So I'm going to say GST fair the test required to map helper equal to donor laws map help our DOT estimates phase that to stream. All right we'll try to adjust an extra 20 dollars so that to be a range. All right okay bombs it is some kind of long code but this really works. Okay so the next we need to do is just set up our estimated time of arrival. So I'm going to say it's yes the time the tests we are called to map helper dot duration stream. All right. So this is the reason why we made that variable probably said I wouldn't be able to assess it from anywhere. All right. OK. All right. So this is all we need to do at this moment. So we just need to go ahead and roll in this and ensure that everything works well. OK. So let's run it up OK. So we're going to set B complication an on Destination bomb so everything works exactly as we planned it. So it's in minutes and our estimates fair is a hundred and twenty dollars to a hundred and forty dollars. So guys this is how to estimate our face. I hope you really enjoy any class so seeing them as class.