Calculate distance from latitude and longitude php, C# – between two points

php get distance between two lat long:  Here is a guide code in PHP for those who are finding how to calculate distance from latitude and longitude. Though you may be using Google Maps and the APIs but when it comes to complete customization you need to get things done via coding.

Methods mentioned here also uses Haversine Formula which is used to calculate the distance between two points.

This code given underneath will calculate the distance between two points if the longitude and latitudes of those two points are already known or given.

Source Code for calculating Distance between two points when latitude and longitude is known:

php distance between two coordinates

Method #1Method #2
most accurate indeed and widely used to embed in any website as geo code

Remember – South latitudes are negative, east longitudes are positive

Values Passed to functions:
lat1, lon1 = Latitude and Longitude of First Point (in decimals)
lat2, lon2 = Latitude and Longitude of Second Point (in decimals)

unit = the unit (Kilometres, Miles, Nautical miles)
where: ‘M’ is statute miles (default)  ,  ‘K’ is kilometers  , ‘N’ is nautical miles

 Haversine Formula 

C# distance between two coordinates

Method #1Method #2

Real Implementation :



Leave a Reply

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