“Get out from smog” – claculate the distance

Get out from smog – part IV

As i mentioned in a previous post. I create a class that will be calculated the distance in kilometers between the measuring stations and a latitudes, longitudes. First we have to calculate distance in kilometers between latidute and longtidute points.

Haversine formula

In this example, I use Haversine formula to calculate distance.

I wrote it in delegate Func which has four parameters and return ‘double’ as a result.

Next I filters my list to receive only stations that are up away max. 100km and added properties which defines the distance from the station.

The whole class looks like this:

And here is test for check the distance between the Main Market Square in Krakow and the Wawel Dragon which is ~1012 meters.

Test class:

get out form smog test

Distance from google maps.

distance from main market square to wawel dragon

Summary

The next step will be combining all written so far functionality and display the nearest station’s.

Link to the project: HERE.

Leave a Reply

Your email address will not be published. Required fields are marked *