WEBVTT 00:05.720 --> 00:12.140 In this video we're going to understand the logic of the search process before diving into our code. 00:12.560 --> 00:19.490 So basically our user is trying to get from a location a to location be. 00:19.910 --> 00:27.260 So the search process is going to look for all troops going from A to B or to be accurate. 00:27.320 --> 00:34.570 He's going to look for all locations or all trips going from near A to B. 00:34.640 --> 00:40.420 So how do we find locations which are near a point. 00:41.140 --> 00:48.780 So let's pick up New Orleans in the U.S. And we want to find all locations which are within a 10 miles 00:48.790 --> 00:51.200 radius from New Orleans. 00:52.940 --> 00:58.730 If you remember when we stored our trips on a database we referred to the location of our troops using 00:58.730 --> 01:01.650 the latitude and longitude. 01:01.690 --> 01:09.430 So we need to convert that's 10 miles radius to a lassitude and longitude language. 01:09.460 --> 01:12.020 So how are we are we going to do that. 01:12.400 --> 01:18.010 Well first let's just have a quick reminder of what these values are just to be comfortable when we 01:18.130 --> 01:19.840 use them in the code. 01:20.440 --> 01:28.930 So the longitude is the angle between that line which goes through the center of the earth and our location. 01:29.200 --> 01:34.550 And that line which is the projection of that line on the equator dusty latitude. 01:34.630 --> 01:43.540 In our case it's 30 degrees the longitude is the angle between the primary region which goes through 01:43.570 --> 01:49.660 Greenwich and south east London and that's Meridian which goes through our location. 01:49.750 --> 01:51.700 So that's the longitude. 01:52.190 --> 01:59.860 So if you starts from this point for example and you travel east you're going to have a lot of plus 01:59.860 --> 02:01.100 10 plus 20. 02:01.120 --> 02:07.060 And if you keep going until the opposite point of this one then you going to get to plus 180 if you 02:07.060 --> 02:13.630 travel west then you're going to get minus 10 minus 20 and so on until you get to the opposite point 02:13.690 --> 02:23.260 of this you're going to get to minus 180 and the points having these two lawyers chutes minus one AC 02:23.260 --> 02:27.560 and one minus plus one AC is going to be the same. 02:27.560 --> 02:35.340 Now the issue is if you travel from this point here I guess you'd have zero trouble up north. 02:35.360 --> 02:39.470 Going to get 30 degrees there and you going to get 90 degrees on the North Pole. 02:39.710 --> 02:46.820 If you trouble cells then you're going to go into negative numbers until minus 90 at the South Pole. 02:46.820 --> 02:57.680 All right so now we want to find locations with which are 10 miles within 10 miles radius from New Orleans. 02:57.690 --> 03:03.600 So how can we convert that to latitude and how can we convert that to longitude. 03:03.600 --> 03:11.440 So it is Soest with the latitude so we are converting 10 miles to last two degrees OK. 03:11.620 --> 03:21.170 If you travel from the North Pole to the south pole through the meridian then the distance you would 03:21.290 --> 03:28.690 travel is going to be twelve thousand four hundred sixty miles and that corresponds to the whole range 03:28.690 --> 03:31.020 between minus 90 and plus 90. 03:31.120 --> 03:38.380 That's a range of 180 degrees so far 10 miles is quite simple. 03:38.450 --> 03:40.590 The result is 10. 03:40.590 --> 03:49.890 Multiply it by one hundred eighty divided by 12 430 and that's our latitude tolerance. 03:50.320 --> 03:51.450 OK. 03:51.460 --> 04:00.130 So all points which are within a 10 miles radius. 04:00.260 --> 04:10.330 But if you travel up north or south OK I'm going to have a lot of shoot of 30 degrees plus minus that 04:10.330 --> 04:11.700 tolerance. 04:11.700 --> 04:12.070 All right. 04:12.070 --> 04:15.150 Now let's move to the longitude. 04:15.160 --> 04:17.320 It's going to be a little bit more complicated. 04:18.470 --> 04:19.180 OK. 04:19.610 --> 04:31.900 So if you travel 10 miles to the west or 10 miles to the east what's Would you get for the longitude 04:32.440 --> 04:37.360 degrees or what is the range of the low degrees. 04:38.200 --> 04:45.360 So let's say that you travel through this whole parallel. 04:45.650 --> 04:46.370 OK. 04:46.760 --> 04:55.180 So the parallel is the this circle or ellipse with points where the same latitude of 30 degrees. 04:55.190 --> 05:01.410 So if you travel through the whole part L was distance would you travel. 05:02.420 --> 05:09.390 Well the answer is going to be you're going to actually travel the same distance that you would travel 05:09.450 --> 05:21.540 at the equator multiplied by coastline of the latitude and that's going to give you twenty four thousand 05:21.540 --> 05:25.980 nine hundred one miles multiplied by the coastline of the multitude. 05:26.580 --> 05:32.550 And that's going to be the distance that you would trouble if you go through this whole parallel. 05:32.550 --> 05:34.440 Now we want only 10 miles. 05:34.470 --> 05:40.460 So the result is going to be that's multiplied by not divided by knots. 05:40.830 --> 05:44.480 And that will give you the tolerance for the longitude. 05:44.920 --> 05:46.070 OK. 05:46.830 --> 05:48.360 Now let's pick up an example. 05:49.350 --> 05:52.280 So let's go to London. 05:52.410 --> 05:54.790 So these are the coordinates of London. 05:55.450 --> 06:02.350 So if we do the math the tolerance for the lassitude is going to be 0.14 degrees and the tolerance for 06:02.350 --> 06:06.830 the longitude is going to be 0.23 degrees degrees. 06:07.220 --> 06:09.910 OK so the license to fly them is 51 points you see one. 06:09.910 --> 06:18.550 So we're looking at a range of fifty one point fifty one plus minus 0.14 that would give you that range. 06:18.580 --> 06:24.130 And now regarding the longitude you're going to look at that number plus minus that tolerance and that 06:24.130 --> 06:26.720 will give us this range. 06:26.740 --> 06:31.740 So what are we looking for locations using a query. 06:31.990 --> 06:38.980 Then inside our query we're going to be looking for a departure longitude for instance between these 06:38.980 --> 06:43.970 two numbers and a departure longitude between these two and. 06:44.530 --> 06:46.420 This pick up another example. 06:47.030 --> 06:51.160 Sydney does the latitude and longitude. 06:51.160 --> 07:00.630 If you do the math you're going to get again 0.14 degrees for the last tolerance and 0.17 for the longitude 07:00.640 --> 07:02.580 tolerance. 07:02.650 --> 07:10.540 So if you do that number plus minus that tolerance gives you that range if you do that number plus minus. 07:10.600 --> 07:13.620 But tolerance will give you that range. 07:13.630 --> 07:16.810 All right. 07:16.960 --> 07:19.700 Now let's pick up another example. 07:20.260 --> 07:25.720 But this time a strange example. 07:26.010 --> 07:26.330 OK. 07:26.340 --> 07:29.930 So this is a location somewhere. 07:30.540 --> 07:30.900 OK. 07:30.900 --> 07:32.970 I don't know the name of the location. 07:33.260 --> 07:41.860 So the last issued is going to be sixty eight point sixty one and the longitude this time is going to 07:41.860 --> 07:46.630 be very close to 180. 07:46.630 --> 07:56.300 So when you do the math you will end up with a range for the lawsuit which is OK but you're going to 07:56.300 --> 08:03.840 end up with a range for the long issued which is not OK because you're going to end that outside 180. 08:03.840 --> 08:06.350 So how do we fix this. 08:06.360 --> 08:20.460 Well anything beyond 180 OK and under one hundred eighty point thirty one is the equivalence of anything 08:21.150 --> 08:27.980 between minus 180 and minus one hundred seventy nine point sixty nine. 08:28.260 --> 08:29.230 So how do we. 08:29.310 --> 08:31.200 How do we get these numbers. 08:31.740 --> 08:43.520 Well if you do one of 80 minus 360 then he still gets the same longitude because you have just traveled 08:45.170 --> 08:49.390 through one whole circle OK or one whole parallel. 08:49.490 --> 08:51.330 If you do the same thing there. 08:51.580 --> 09:02.350 One hundred eighty point thirty one minus to 360 you will still get the same longitude OK. 09:02.570 --> 09:09.590 To be more precise or let's make it a little bit clear if you travel from that points. 09:10.190 --> 09:10.630 OK. 09:10.730 --> 09:15.120 And you do a whole circle then you're going to end up in the same points. 09:15.740 --> 09:28.280 So 0 is the equivalent of minus 360 if you travel from 60 OK and you do one all around and you come 09:28.280 --> 09:29.470 back to the same points. 09:30.810 --> 09:38.240 Then you're going to get 360 plus 360 that's going to be 420. 09:38.240 --> 09:41.390 So 420 is the equivalent of 60. 09:41.420 --> 09:42.320 All right. 09:42.320 --> 09:45.780 And the same thing applies if you travel west instead of east. 09:45.890 --> 09:46.730 OK. 09:46.730 --> 09:51.200 So if you go from there and you travel west that means that you're going to be doing minus 360. 09:51.290 --> 09:58.610 So 60 minus 360 that will give you minus three hundred sixty is the equivalent of minus 300. 09:58.610 --> 09:58.910 All right 10:02.800 --> 10:06.280 so we're going to end up with two intervals. 10:06.340 --> 10:13.570 So when we run out queery we're going to look for departure to choose between these two numbers and 10:14.670 --> 10:17.970 or the partially choose between these two areas. 10:18.040 --> 10:18.830 OK. 10:19.270 --> 10:24.740 Now let's look at an extreme and extreme case for the latitude this time. 10:25.090 --> 10:29.650 So we're going to pick up a point with a lot itude which is very close to 90. 10:30.010 --> 10:37.030 So when we do our muts we end up with longitude which is within the right range but we're going to end 10:37.030 --> 10:40.480 up with a lot issued between these two numbers. 10:40.670 --> 10:43.220 And we're going to go beyond 90. 10:43.520 --> 10:51.380 So this interval is the equivalence of that one 10:55.960 --> 10:59.960 so what does it mean. 10:59.960 --> 11:04.430 Well let's go back to figure. 11:04.610 --> 11:17.420 So if you start from this point and you travel for 0.05 to get to a latitude of ninety point zero or 11:17.430 --> 11:19.300 five. 11:19.430 --> 11:22.770 So let's say that this is ninety point zero five. 11:22.790 --> 11:24.130 It's not exactly about but it's just. 11:24.170 --> 11:25.450 Just for clarity. 11:25.530 --> 11:27.240 So ninety 0 5. 11:27.320 --> 11:38.720 Be right there so we traveled zero point zero degrees all points on that's Barwell behalf. 11:38.780 --> 11:49.810 The same latitude so that one actually has got 90 points zero 5 and that's one as well should have ninety 11:49.810 --> 11:50.840 point zero or five. 11:51.010 --> 11:56.130 But it's also has got 90 minus 0.05. 11:56.140 --> 11:57.100 All right. 11:57.220 --> 12:04.390 So anything between 90 and ninety point zero or five is the same as anything between this point which 12:04.390 --> 12:08.330 is 90 minus 0.05 and 90. 12:08.470 --> 12:16.690 So the interval 90 to ninety point zero zero five is the same as the interval between eighty nine point 12:16.780 --> 12:19.050 ninety five and ninety 12:24.010 --> 12:28.510 So this is going to be the same as this. 12:28.940 --> 12:30.160 OK. 12:30.990 --> 12:37.970 Because if we go from ninety nine point ninety five to 90 it's still within that interval. 12:38.100 --> 12:38.850 OK. 12:38.850 --> 12:43.620 So instead of saying between that and that we're just going to say it's going to be between that and 12:43.620 --> 12:46.420 the maximum which is 90. 12:46.430 --> 12:46.940 All right. 12:46.940 --> 12:48.800 So hopefully this is clear. 12:49.590 --> 12:52.910 Now let's see how are we going to build our query. 12:53.330 --> 12:54.410 So let's pick up an example. 12:54.410 --> 12:56.250 So this is our departure. 12:56.570 --> 13:00.460 These are the latitude and longitude of the departure. 13:00.890 --> 13:02.480 And this is our destination. 13:02.600 --> 13:03.650 I picked up Sydney. 13:03.770 --> 13:08.650 So that's the latitude and longitude. 13:09.210 --> 13:11.620 So is due to months. 13:11.720 --> 13:14.990 So the range for that lawsuit is going to be that's what does that mean. 13:15.080 --> 13:21.680 And that's the months regarding the longitude we were having a lot issued out of range. 13:21.680 --> 13:23.940 So we end up with two intervals. 13:28.210 --> 13:34.930 So when we look at the departure in the query we're going to say the parsha latitude between that and 13:34.940 --> 13:45.110 about and departure longitude either greater than that or smaller than that's ok. 13:45.280 --> 13:50.390 Now when we go to the destination everything is within the right range. 13:50.410 --> 13:55.620 So the latitude is going to be between this and this. 13:55.720 --> 14:01.580 The lawsuit is going to be between that and that's and that's our equerry OK. 14:02.090 --> 14:10.490 So make sure that you understand this properly before moving to the next video where we going to write 14:10.520 --> 14:12.700 code and build our query.