We have a 'geocoding' example
here, and indeed I was using it earlier today. The idea is that someone enters part of an address on your web site, and you contact Google to look up the latitude and longitude so that you can put it on a map, or calculate a distance from somewhere else. It's very need, but it needs a bit more that a basic knowledge of PHP to debug - you've got multiple servers, security keys and configuration options floating around.
So it was a co-incidence, but no surprise, to find the following in my mail box later on:
Dear Sir,
While I was searching for a script that allows simple geocoding with google api I found this article in your website:
http://www.wellho.net/resources/ex.php4?item=h999/loclook.php
When I tried to test it in my localhost it showed me this error:
Warning: file(http://maps.google.com/maps/geo?q=paris &output=csv&key=key) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\AppServ\www\goo\t.php on line 12
I don't really know where the problem is; I would appreciate help.
|
I've never met the poster ... but the question is well formed (I have tidied up the English for publication here), specific and polite and I want to help ... and to help others who come across the same thing. So - here's my answer:
The problem lies in the attempt to contact Google for the information - in the source code line within the error message you have quoted.
This line can fail for a number of reasons:
a) Your server / PHP may be configured so that it does not allow outgoing http requests
b) Your server may not be correctly resolving the DNS / name of maps.google.com
c) There may be an error in the URL that you have called up at Google, so that you are pointing to a page that does not exist there
d) You may have an extra space or other spurious character in the part of the URL after the ?
e) You may not have the correct / a recognised Google key.
The error message tells me that your problem is (c), but the piece of code in the error message looks correct. The best advise I can offer is to try the lookup on Google directly rather than via your PHP script (make sure that works first). Then try contacting another server from yours - not the Google one with the extra complexity of the key, but something else. Then try bringing the code together. This series of tests will narrow down the problem - tell you if it is one of the five reasons I have suggested or something else - which in turn will let you solve the problem.
Graham
(written 2009-08-14 22:31:12)
Associated topics are indexed under
H309 - PHP - Maps, Graphics and Geographics [2675] Redirecting to your main domain for correct security keys - (2010-03-13)
[2583] Reducing image size on digital photos - PHP - (2010-01-17)
[2390] Dynamic / changing images on your web page - (2009-09-01)
[2343] World Flags in your PHP pages - (2009-08-10)
[1956] Images for Christmas - (2008-12-21)
[1923] Making it all worthwhile - (2008-12-04)
[1756] Ever had One of THOSE mornings? - (2008-08-16)
[1752] Dynamic maps / geographics in PHP - (2008-08-13)
[1734] All around the world? - (2008-08-03)
[1724] addslashes v mysql_real_escape_string in PHP - (2008-07-27)
[1628] Gant charts - drawing them with a PHP script - (2008-05-03)
[1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
[1390] Converting from postal address to latitude / longitude - (2007-10-13)
[1389] Controlling and labelling Google maps via PHP - (2007-10-13)
[1194] Drawing hands on a clock face - PHP - (2007-05-19)
[1104] Drawing dynamic graphs in PHP - (2007-03-09)
[937] Display an image from a MySQL database in a web page via PHP - (2006-11-22)
[665] PHP Image viewing application - (2006-04-01)
[563] Merging pictures using PHP and GD - (2006-01-13)
[320] Ordnance Survey - using a 'Get a map' - (2005-05-22)
Some other Articles
Counting Words in Python via the webGetting it right from the start - new programmersAlpaca Case or Camel CaseThornham Farm Shop, Seend Cleeve, nr MelkshamGeocoding - converting address to latitude / Longitude with PHP via GoogleError Handling in Lua with assert and pcallA fresh example - objects the Lua wayEncapsulating shared code in a Lua moduleChecking if the user has entered a number (Lua)Passing multiple results back from a function - Lua, Python, etc