I will just post it here @tomkomin then everyone can see it.
It’s pretty basic and simply uses html meta-refresh to send a query every second until they are all done but it works
It echos messages about what is has done as it processes so you can see it’s progress
Just copy and paste it into a blank page and make the appropriate modifications
<html><head>
<?php
$connection = new PDO('mysql:host=yourdatabasehostname;dbname=yourdatabasename;charset=utf8', 'yourusername', 'yourpassword');
?>
<meta charset="utf-8">
<meta http-equiv="refresh" content="1">
<title>Geocoder</title>
</head>
<body>
<?php
/*
database fields used are as follows, datatype i use shown:
lat - latitude Type:Decimal 10.6
lng - longitude Type:Decimal 10.6
FullAddress - Full address of property to geocode
isgeo - database field used to record if address is geocoded, 0 = no, 1 = yes, 2 = geocoding failed (Type:smallint)
geoaddress - stored the address returned by google when an address is successfully geocoded (optional)
ID - unique id of the record
*/
$STH = $connection -> prepare( "SELECT count(*) as datacount FROM <yourtablename> where isgeo = 0" );
$STH -> execute();
$result = $STH -> fetch();
echo "hits:".$result["datacount"]."<br/>";
$qry="SELECT * FROM <yourtablename> where isgeo = 0 limit 1";
foreach($connection->query($qry) as $row) {
// get latlang
$address=$row["FullAddress"];
$id=$row["ID"];
$address_enc=str_replace(" ","+",$address);
echo $address;
$url ="https://maps.googleapis.com/maps/api/geocode/xml?address=".$address_enc."+UK&sensor=false&key=YourGoogleAPIKeyHere";
echo $url;
$xml = simplexml_load_file($url);
print"<br/><pre>";
print_r($xml);
echo $xml->Status; // US
$status = $xml->status;
if ($status=="OK") {
$Lat = $xml->result->geometry->location->lat;
$Lng = $xml->result->geometry->location->lng;
$geoaddress = $xml->result->formatted_address;
$LatLng = "$Lat,$Lng";
$isgeo = 1;
$statement = $connection->prepare("update <yourtablename> set lat = :lat, lng = :lng, isgeo = :isgeo, geoaddress = :geoaddress where ID = :id");
$statement->execute(array(
"lat" => $Lat,
"lng" => $Lng,
"isgeo"=> $isgeo,
"geoaddress" => $geoaddress,
"id" => $id
));
echo "<br/>";
echo $row["ID"];
echo " - ";
echo $row["Full Address"];
echo " - ";
echo $row["lat"];
echo " - ";
echo $row["lng"];
echo " - ";
echo $row["isgeo"];
echo " - ";
echo $geoaddress;
print"<br/><pre>";
print_r($xml);
echo $xml->Status; // US
}
if ($status=="ZERO_RESULTS") {
$statement = $connection->prepare("update <yourtablename> set lat = :lat, lng = :lng, isgeo = :isgeo, geoaddress = :geoaddress where ID = :id");
$statement->execute(array(
"lat" => 0,
"lng" => 0,
"isgeo" => 2,
"geoaddress" => "",
"id" => $id
));
echo $xml->status;
}
}
?>
</body></html>