millercj Posted February 17, 2009 Share Posted February 17, 2009 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? Quote Link to comment Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 You will probably need to use the google api, not sure, but that should allow you to pull different information. http://code.google.com/apis/maps/index.html Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 17, 2009 Share Posted February 17, 2009 yeah, this should be the part of the API you need: http://code.google.com/apis/maps/documentation/reference.html#GDirections Quote Link to comment Share on other sites More sharing options...
millercj Posted February 17, 2009 Author Share Posted February 17, 2009 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];} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.