By Fagault Eric on Thursday, 11 October 2018
Posted in General Issues
Likes 0
Views 339
Votes 0
Hello,
In the workflow used for the creation of new pages, I added a Numerical field and an Address field, I would like to know if the Address field makes it possible to store the GPS coordinates?
In this case, how could I recover them?
Best regards.
Eric
Hi there,

From what i understand, you wanted to get those coordinate from address fields? If yes, you can check them here .../media/com_easysocial/apps/fields/user/address/address.php

If not, it would be best if you can provide us with more details so that we can have a better understanding. Please advice.
·
Friday, 12 October 2018 11:44
·
0 Likes
·
0 Votes
·
0 Comments
·
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
·
Friday, 12 October 2018 16:43
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi there,

Nice job there Eric.

Just for your information, I have locked and marked this thread as resolved to avoid confusions in the future. Please start a new thread if you have any other issue in the future so it will be easier for us to manage your inquiries.

Thanks for understanding.
·
Friday, 12 October 2018 17:02
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post