Calculate Distance From Latitude and Longitude PHP

By | August 23, 2015

Calculating distance from latitude and longitude is bit tricky and complex. Recently we were working on a project and we need to calculate the longitude and latitude from given longitude and latitude. We use to show the nearest restaurant’s using our location. We got success so i think to put it online so that it will help you guy’s. Soon we will put this example in most of the programming language. Right now it is in PHP.

Calculate Distance from Latitude and Longitude Using PHP

We have created a function for it and we are putting this function here.

It will take 5 parameter’s which are as follows.

  • $lat1 = Your Latitude
  • $lon1 = Your Longitude
  • $lat2 = Searched Latitude
  • $lon2 = Searched Longitude
  • $unit = K for kilometer, N for Nautical Miles, Leave it blank will show Miles.

Hope it will help you in your project and you like our tutorial. Please share it with other’s if you have any issue please let us know comment below it will be happy to help you. Thank You

~~~~Happy Coding~~~~

2 thoughts on “Calculate Distance From Latitude and Longitude PHP

  1. Stan

    Are you sure this works? The distances being returned are way off….

    Reply

Leave a Reply

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