Thank you very much for your answer.
I went to Google documentation and used what it offers.
class GmapApi {
private static $apikey = 'AIzaSyBhk724-XKwWj-fHS3jP3FWSaqoX1633fE';
public static function geocodeAddress($address) {
//valeurs vide par défaut
$data = array('lat' => '', 'lng' => '');
//on formate l'adresse
$address = str_replace(" ", "+", $address);
//on fait l'appel à l'API google map pour géocoder cette adresse
$json = file_get_contents("https://maps.google.com/maps/api/geocode/json?key=" . self::$apikey . "&address=$address&sensor=false®ion=fr");
$json = json_decode($json);
//on enregistre les résultats recherchés
if ($json->status == 'OK' && count($json->results) > 0) {
$res = $json->results[0];
//adresse complète et latitude/longitude
//$data['address'] = $res->formatted_address;
$data['lat'] = $res->geometry->location->lat;
$data['lng'] = $res->geometry->location->lng;
}
return $data;
}
}
$data = GmapApi::geocodeAddress($adress);
//on affiche les différente infos
//echo $data['lat'];
//echo $data['lng'];
$coma = ",";
$lat = "lat:";
$lng = "lng:";
$Coordonnees = $lat." ".$data['lat']." ".$coma." ".$lng." ".$data['lng'];
//echo $Coordonnees;
?>
<!-- Afficher la carte -->
<link rel="stylesheet" href="/maps/documentation/javascript/cgc/demos.css">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBhk724-XKwWj-fHS3jP3FWSaqoX1633fE&callback=initMap"
async defer></script>
<div id="map" style="width:100%; height:100px; margin: 10px 0px; display:<?php echo "$displayAddress"; ?>;"></div>
<script>
function initMap() {
//var myLatLng = {lat:-25.363,lng:131.044};
var myLatLng = {<?php echo $Coordonnees; ?>};
// Create a map object and specify the DOM element
// for display.
var map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 8
});
// Create a marker and set its position.
var marker = new google.maps.Marker({
map: map,
position: myLatLng,
//title: '<?php echo $page->getName();?>'
});
}
</script>
Is this a good solution?
Best regards?
Eric