PHP Classes

PHP Distance Calculator: Calculate distance between places with Maps API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-10 (9 months ago) RSS 2.0 feedStarStarStar 54%Total: 656 All time: 4,901 This week: 61Up
Version License PHP version Categories
distance-finder 1.9GNU General Publi...5.3PHP 5, Web services, Geography
Description 

Author

This class can calculate the distance between two places with the Google Maps API.

It can take the address of two locations and sends HTTP requests to the Google Maps API to retrieve the distance to be traversed to go from one location to the other.

The calculated distance can be geographic, or traversed by car, bycicle or walking. The distance may be returned in miles or kilometers.

This class calculates distance between two given Addresses or given two pair of latitudes and longitudes.

It can calculate Geographical Distance, Car Driving Distance, Walking Distance and Bicycle Distance.

It returns the result in Kilometer and/or Miles as per your configuration.

Picture of Tariqul Islam
  Performance   Level  
Name: Tariqul Islam <contact>
Classes: 3 packages by
Country: Bangladesh Bangladesh
Age: 44
All time rank: 189627 in Bangladesh Bangladesh
Week rank: 214 Up3 in Bangladesh Bangladesh Up

Example

<?php
include "distancefinder.class.php";

//Calculate Car Driving Distance in Kilometer from two Addresses
$df = new distanceFinder("Car Drive");
$result = $df->findDistance("795 E DRAGRAM, TUCSON AZ 85705, USA", "300 BOYLSTON AVE E, SEATTLE WA 98102, USA");
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Car Driving Distance is: " . $result . " Kilometer.<br />";
}

//Calculate Walking Distance in Kilometer from two Addresses
$df = new distanceFinder("Walking");
$result = $df->findDistance("795 E DRAGRAM, TUCSON AZ 85705, USA", "300 BOYLSTON AVE E, SEATTLE WA 98102, USA");
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Walking Distance is: " . $result . " Kilometer.<br />";
}

//Calculate Bicycle Distance in Kilometer from two Addresses
$df = new distanceFinder("Bicycle");
$result = $df->findDistance("795 E DRAGRAM, TUCSON AZ 85705, USA", "300 BOYLSTON AVE E, SEATTLE WA 98102, USA");
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Bicycle Distance is: " . $result . " Kilometer.<br />";
}

//Calculate Geographical Distance in Kilometer from two Addresses
$df = new distanceFinder("Geographic");
$result = $df->findDistance("795 E DRAGRAM, TUCSON AZ 85705, USA", "300 BOYLSTON AVE E, SEATTLE WA 98102, USA");
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Geographic Distance is: " . $result . " Kilometer.<br />";
}

//Calculate Geographical Distance in Kilometer from two pairs of Latitude and Longitude
$df = new distanceFinder("Geographic");
$result = $df->findDistance(array("32.2680738", "-110.9923904"), array("47.6210785", "-122.323045"));
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Geographic Distance is: " . $result . " Kilometer.<br />";
}

//Calculate Geographical Distance in Mile from two pairs of Latitude and Longitude
$df = new distanceFinder("Geographic");
$df->setDistanceUnit("Mile");
$result = $df->findDistance(array("32.2680738", "-110.9923904"), array("47.6210785", "-122.323045"));
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Geographic Distance is: " . $result . " Mile.<br />";
}

//Calculate Geographical Distance in Kilometer and Mile from two pairs of Latitude and Longitude
$df = new distanceFinder("Geographic");
$df->setDistanceUnit("All");
$result = $df->findDistance(array("32.2680738", "-110.9923904"), array("47.6210785", "-122.323045"));
if (isset(
$result['error'])) {
    echo
$result['error']['msg'];
} else {
    echo
"Geographic Distance is: " . $result['Mile'] . " Mile or ". $result['KM'] . " Kilometer.<br />";
}

?>


  Files folder image Files (3)  
File Role Description
Plain text file distancefinder.class.php Class Main Class File
Accessible without login Plain text file example.php Example Example of Use
Accessible without login Plain text file output.php Aux. Output File

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:656
This week:0
All time:4,901
This week:61Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:66%StarStarStarStar
Documentation:-
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:54%StarStarStar
Rank:2011