0

i am looking for some help to find the distance between two address through php as i can not use the google maps api. so get a way from this post

Distance between two addresses

but i need to know how can send the request using URL pattern and grab the repose to save them in database.

http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false

thanks for any suggestion.

///////////////

After these answers i am there

     $customer_address_url =  urlencode($customer_address);
     $merchant_address_url =  urlencode($merchant_address);

     $map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";

      $response_xml_data = file_get_contents($map_url);
      $data = simplexml_load_string($response_xml_data);

XML response is visible when i put this url : http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false

but can not printing through

      echo "<pre>"; print_r($data); exit;  
Community
  • 1
  • 1
Asif hhh
  • 1,552
  • 3
  • 15
  • 27
  • Check out the following functions: [`http_build_query`](http://php.net/manual/en/function.http-build-query.php), [`file_get_contents`](http://php.net/manual/en/function.file-get-contents.php) and [`simplexml_load_string`](http://php.net/manual/en/function.simplexml-load-string.php). – vstm Sep 22 '12 at 05:36
  • Thanks these functions are too helpful. i set my logic there but can not print the xml response from $data = simplexml_load_string($response_xml_data); echo "
    "; print_r($data); exit;
    – Asif hhh Sep 22 '12 at 07:52

2 Answers2

0

You can try this..

$url = "http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false";
$data = file_get_contents($url);

Now $data contains resulting xml data. You can parse this xml data using..

http://php.net/manual/simplexml.examples.php

Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59
0

use the haversine formula

Also check https://developers.google.com/maps/documentation/distancematrix/

mymotherland
  • 7,968
  • 14
  • 65
  • 122