Re: Calculating driving distance between UK postcodes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 4, 2012 at 9:18 AM, Terry Ally (Gmail) <terryally@xxxxxxxxx> wrote:
> Google works in Javascript extensively - not a language with which I
> have in-depth experience hence my reason for asking for PHP solution.
>
> For example the following will get me a JSON output with the distance in
> Kms and time. I don't know how to get PHP to read this information and
> extract just the distance. I need the distance so that I can calculate cost
> of a trip.
>
> <form id="google" action="
> http://maps.googleapis.com/maps/api/distancematrix/json"; method="get">
> <input type="text" name="origins" value="" />
> <input type="text" name="destinations" value="" />
> <input type="hidden" name="sensor" value="false">
> <input type="hidden" name="submitted" value="1">
> <br><a type="submit"
> onClick="document.getElementById('google').submit()"><strong><strong>Get
> Distance</strong></strong></a>
> </form>

Using Google Maps API is pretty straight-forward. You don't need to
set up a form or a use a POST to get the info. This page should
describes how to use a standard GET query to get the info you want:

< https://developers.google.com/maps/documentation/distancematrix/ >

Setting up the proper URL to call, you can activate it using
file_get_contents provided you have allow_url_fopen set to true in
php.ini. (Do make sure to check for possible errors returned.)

You can get the response back as either JSON or XML, both of which PHP
can parse into useful data structures:

< http://us.php.net/manual/en/function.json-decode.php >

< http://us.php.net/manual/en/book.simplexml.php >

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux