Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Geocoding - converting address to latitude / Longitude with PHP via Google

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, updated 2009-08-15)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H309 - PHP - Maps, Graphics and Geographics
  [320] Ordnance Survey - using a 'Get a map' - (2005-05-22)
  [563] Merging pictures using PHP and GD - (2006-01-13)
  [665] PHP Image viewing application - (2006-04-01)
  [937] Display an image from a MySQL database in a web page via PHP - (2006-11-22)
  [1104] Drawing dynamic graphs in PHP - (2007-03-09)
  [1194] Drawing hands on a clock face - PHP - (2007-05-19)
  [1389] Controlling and labelling Google maps via PHP - (2007-10-13)
  [1390] Converting from postal address to latitude / longitude - (2007-10-13)
  [1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
  [1628] Gant charts - drawing them with a PHP script - (2008-05-03)
  [1724] addslashes v mysql_real_escape_string in PHP - (2008-07-27)
  [1734] All around the world? - (2008-08-03)
  [1752] Dynamic maps / geographics in PHP - (2008-08-13)
  [1756] Ever had One of THOSE mornings? - (2008-08-16)
  [1923] Making it all worthwhile - (2008-12-04)
  [1956] Images for Christmas - (2008-12-21)
  [2343] World Flags in your PHP pages - (2009-08-10)
  [2390] Dynamic / changing images on your web page - (2009-09-01)
  [2583] Reducing image size on digital photos - PHP - (2010-01-17)
  [2675] Redirecting to your main domain for correct security keys - (2010-03-13)
  [2729] Uploading a document or image to its own URL via a browser - (2010-04-18)
  [2939] Protecting your images from use out of context - (2010-08-29)
  [3027] Server logs - drawing a graph of gathered data - (2010-11-03)
  [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)
  [3197] Finding and diverting image requests from rogue domains - (2011-03-08)
  [3211] Computer Graphics in PHP - World (incoming data) to Pixel (screen) conversion - (2011-03-24)
  [3447] Needle in a haystack - finding the web server overload - (2011-09-18)
  [3536] UK Mapping Data - and more to come - under government Open Data measures - (2011-12-03)
  [3584] QR codes - graphics images that provide quick phone links - (2012-01-18)
  [3734] QR codes with marketing logos embedded - (2012-05-16)
  [3817] Fpdf - generating .pdf documents easily from your PHP program - (2012-07-24)
  [4178] Where are you? How to write a geosensitive application - (2013-09-18)
  [4365] The changing face of Christmas - (2014-12-26)
  [4437] Adding a PHP build option, rotating an image based on camera data, and a new look at thumbnails in PHP - (2015-02-22)
  [4655] Image indexer / thumbnail display scripts in PHP - (2016-02-25)


Back to
Error Handling in Lua with assert and pcall
Previous and next
or
Horse's mouth home
Forward to
Thornham Farm Shop, Seend Cleeve, nr Melksham
Some other Articles
Counting Words in Python via the web
Getting it right from the start - new programmers
Alpaca Case or Camel Case
Thornham Farm Shop, Seend Cleeve, nr Melksham
Geocoding - converting address to latitude / Longitude with PHP via Google
Error Handling in Lua with assert and pcall
A fresh example - objects the Lua way
Encapsulating shared code in a Lua module
Checking if the user has entered a number (Lua)
Passing multiple results back from a function - Lua, Python, etc
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2361_Geo ... oogle.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb