$key) {
if(str_replace($domain,"",$_SERVER['SERVER_NAME']).$domain == $_SERVER['SERVER_NAME']) {
$google_maps_key = $key;
}
}
}
}
$delay = 200000; // usecs before each fetching
$base_url = "http://maps.google.ch/maps/geo?output=csv&key=".$google_maps_key;
$first_fetch = true;
$cache_write = true;
$has_620 = false;
$single_address = false;
$addresses = Addresses::withSearchString($searchstring, $alphabet);
$result = $addresses->getResults();
$coords = array();
// foreach($addresses as $address) {
while($myrow = mysqli_fetch_array($result)) {
$coord['addr'] = trim(str_replace("\n", ", ", trim($myrow['address'])),",");
$coord['html'] = "".$myrow['firstname'].(isset($myrow['middlename']) ? " ".$myrow['middlename'] : "")." ".$myrow['lastname']."
";
$coord['html'] .= ($myrow['company'] != "" ? "".$myrow['company']."
" : "");
$coord['html'] .= str_replace("\n","",str_replace("\r","",nl2br($myrow['address'])));
$coord['id'] = $myrow['id'];
$coord['long'] = $myrow['addr_long'];
$coord['lati'] = $myrow['addr_lat'];
$coord['status'] = $myrow['addr_status'];
//
// Geo-code if long/lat is not yet defined
//
if(!($coord['status'] == 200 || $coord['status'] == 602 )) {
$request_url = $base_url . "&q=" . urlencode($coord['addr']);
if($first_fetch) usleep($delay);
$first_fetch = false;
$csv = file_get_contents($request_url) or die("url not loading");
$csvSplit = explode(",", $csv);
// http://code.google.com/intl/de-DE/apis/maps/documentation/javascript/v2/reference.html#GGeoStatusCode
$coord['status'] = $csvSplit[0];
if($coord['status'] == 200) {
$coord['lati'] = $csvSplit[2];
$coord['long'] = $csvSplit[3];
$sql = "UPDATE $table
SET addr_long = '".$coord['long']."'
, addr_lat = '".$coord['lati']."'
, addr_status = '".$coord['status']."'
WHERE id = '".$myrow['id']."'
AND domain_id = '$domain_id'
AND deprecated is null;";
$upd_result = mysqli_query($db,$sql);
} else {
$sql = "UPDATE $table
SET addr_status = '".$coord['status']."'
WHERE id = '".$myrow['id']."'
AND domain_id = '$domain_id'
AND deprecated is null;";
$upd_result = mysqli_query($db,$sql);
}
}
$coords[] = $coord;
}
if($single_address) {
$coords = array();
$coords[] = $single_coord;
}
//
// Concat multiple entries on one place:
// * Sort places
// * Concat content
//
$longs = array();
$latis = array();
foreach ($coords as $key => $coord) {
$longs[$key] = $coord['long'];
$latis[$key] = $coord['lati'];
$coords[$key]['bubble'] = $coord['html']."
";
$coords[$key]['bubble'] .= "...".msg('MORE')."";
}
array_multisort($longs, SORT_ASC, $latis, SORT_ASC, $coords);
// print_r($coords);
?>