Jump to content

Recommended Posts

I'm building a website for my client with an e-commerce component. She wants to offer free delivery if the address of the buyer is within 30 driving miles of her home. I know if I go to the URL:

 

http://maps.google.com/maps?q=from+A+to+B&output=kml

 

with A being the starting address and B being the ending address it will return the data in which that information is encoded. Is there a way to do something like this within the backend so the consumer never sees anything?

Link to comment
https://forums.phpfreaks.com/topic/145570-solved-calculate-driving-distance/
Share on other sites

i figured out that I can do it with ajax without api's:

 

$prepa = "XXXX";
$prepb = "XXXX";
$a=urlencode($prepa);
$b=urlencode($prepb);
//Create the url
$myurl = "http://maps.google.com/maps?q=from+{$a}+to+{$b}&output=kml";
//Open the url
$f = fopen ($myurl, "r");
//Read the contents
$str = stream_get_contents($f);
//String match the distance
preg_match("/Distance: ([0-9.-]+)/", $str, $distance);
preg_match("/#160;([a-z]+)/", $str, $units);
//Respond

if($distance[1]!=NULL && $distance[1]<30)
{echo "Eligible for Delivery".$distance[1].$units[1];}
else{echo "Not Eligible for Delivery ".$distance[1].$units[1];}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.