function distanceBetweenzipcodes($zipcode, $zipcode2){
try{
$url ="https://maps.googleapis.com/maps/api/distancematrix/json?origins=".$zipcode."&destinations=".$zipcode2."&mode=car&sensor=false&key=";
$details=file_get_contents($url);
$result = json_decode($details,true);
$distance = $result['rows'][0]['elements'][0]['distance']['value'] ?? 0;
if($distance==0){
return 0;
}
return $distance/1000;
}
catch(\Exception $e){
return 0;
}
}
echo distanceBetweenzipcodes(127021,127031);
#calculate distance between two zipcode. please pass google map api key to this method
-
Notifications
You must be signed in to change notification settings - Fork 0
ashishbansal-kmc/distance-between-zipcode
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
calculate distance between two zipcodes using google map api
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published