Hello
I am new to the forum but not new to PHP. I used to do a hell fo a lot of programming but since startign a new job I havent done any.
Using Google Maps you can put a link into your URL which will calculate a a router and display the route using the URL.
Example:
http://maps.google.co.uk/maps?f=d&sourc ... &doflg=ptm
This will load the route and give directions.
Now if you put "&output=kml" on the end of the URL, this will initiate a file download of all the information, this file can be opened in Notepad. In part of this file it says "Distance" followed by a number in decimals. Which is the distance between the two destinations that are highlighed in the URL.
I need to get this distance into a variable using a web form. So the user puts in start and end postcodes into a form and hits submit. This will then insert the two postcodes into a URL, then I want the PHP code to download, open and find the Distance: 5.10 and put the "5.10" in the PHP code as a variable, so that I can then perform more calculations.
Am I correct in saying that PHP can do this using something along the lines of fopen command? Or would it be something completly different and advanced?
Thanks, any Help is much appriciated.
Simon
File Manipulation
Moderator: General Moderators
-
ajith_rock
- Forum Newbie
- Posts: 11
- Joined: Wed Sep 08, 2010 2:37 am
Re: File Manipulation
Dear Simon,
Adding &output=kml will be downloading the file on the cilent side. Search for an attribute(I mean a 'get:name,value' pair) that will allow you to send the information to the server. If thats possible, then reading the data from the .kml file, and extracting the information you need is pretty simple.
For file operations : http://www.tizag.com/phpT/fileread.php is a good place to start.
A simple birds eye algorithm would be :
1. Read the file,
2. Use reg ex to find the data that you need.
3. Store it in the var, and use it for further processing
Best,
--
Ajith
Adding &output=kml will be downloading the file on the cilent side. Search for an attribute(I mean a 'get:name,value' pair) that will allow you to send the information to the server. If thats possible, then reading the data from the .kml file, and extracting the information you need is pretty simple.
For file operations : http://www.tizag.com/phpT/fileread.php is a good place to start.
A simple birds eye algorithm would be :
1. Read the file,
2. Use reg ex to find the data that you need.
3. Store it in the var, and use it for further processing
Best,
--
Ajith
-
simonprince
- Forum Newbie
- Posts: 4
- Joined: Thu Sep 09, 2010 7:48 am
Re: File Manipulation
Hello
Thanks for your help on this. I have been looking into it more and more.
I have used the following to try and display either the Source HTML that also contains the distance and the output file. But cannot get it to work. on the HTML out put I get a 400 Bad Request error.
I am assuming that the syntax is correct and it should spit out the html as I have tested it with another web page. Would the reason be why its not working be caused by google not allowing this to happen?
Notice that the output on the URL is "html" if this is changed to "kml" I get the same output (400 Bad Request).
http://www.sprince.co.uk/calculations.p ... mit=Submit
If you have any futher ideas on how I can get this to work I would be greatful, or infact to be told it quite simpily it cannot be done.
NB: $saddr and $daddr are variables that are submitted to page via a web form.
Thanks for your help on this. I have been looking into it more and more.
I have used the following to try and display either the Source HTML that also contains the distance and the output file. But cannot get it to work. on the HTML out put I get a 400 Bad Request error.
Code: Select all
<?php
$url = "http://maps.google.co.uk/maps?f=d&source=s d&saddr=$saddr&daddr=$daddr&doflg=ptm&output=html";
$lines = file($url);
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
?>
Notice that the output on the URL is "html" if this is changed to "kml" I get the same output (400 Bad Request).
http://www.sprince.co.uk/calculations.p ... mit=Submit
If you have any futher ideas on how I can get this to work I would be greatful, or infact to be told it quite simpily it cannot be done.
NB: $saddr and $daddr are variables that are submitted to page via a web form.
-
simonprince
- Forum Newbie
- Posts: 4
- Joined: Thu Sep 09, 2010 7:48 am
Re: File Manipulation
Can this post be moved to the Code section, I think I have posted in the wrong location.
Thanks
Thanks