<?php
ini_set('display_errors',1);
header('Content-Type: text/html; charset=utf-8');

include('config/config.inc.php');
include('config/lib.inc.php');
exit();

$maCleDeCryptage = getCleDeCryptage();
$query="select * from eta where lat='0.0000000000' and lon='0.0000000000'";
//$query="select * from eta where id_eta>409";	
$db = connect_base();
$queryRequest = $db->prepare( $query );
$queryRequest->execute();
if($queryRequest->rowCount()>0){
	$data=$queryRequest->fetchAll();
	
	foreach($data as $cle=>$val){
		$add=decrypter($maCleDeCryptage,$val['adresse1'])." ";
		$add.=decrypter($maCleDeCryptage,$val['adresse2'])." ";
		$add.=decrypter($maCleDeCryptage,$val['cp'])." ";
		$add.=decrypter($maCleDeCryptage,$val['ville']);
		echo $add.'<br /><br />';
		$url_gmap    = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode(utf8_encode($add)) . '&sensor=false&key=AIzaSyAD8dr4sS_iFafcU_AowzS9p9B306iQEZQ';
		$json        = json_decode(file_get_contents($url_gmap), true);
		$coord       = $json['results']['0']['geometry']['location'];
		//$file2[$line] = $content . ';' . $coord['lat'] . ';' . $coord['lng'];
		echo "<br>";		echo "Lat : ".$coord['lat'];
		echo "<br>";
		echo "Lon : ".$coord['lng'];
		echo "<br>";		echo "<br>";		echo "<br>";	
	$query2="update eta set lat=:lat, lon=:lon where id_eta=:id_eta";
	$db2 = connect_base();
	$queryRequest2 = $db2->prepare( $query2 );
	$queryRequest2->bindParam( ':id_eta', $val['id_eta'], PDO::PARAM_INT );
	$queryRequest2->bindParam( ':lat', $coord['lat'], PDO::PARAM_STR);
	$queryRequest2->bindParam( ':lon', $coord['lng'], PDO::PARAM_STR );
	$queryRequest2->execute();

	}
}



?>