diff --git a/src/EcclesiaCRM/utils/GeoUtils.php b/src/EcclesiaCRM/utils/GeoUtils.php index ef1eb5a0a..0911dba26 100644 --- a/src/EcclesiaCRM/utils/GeoUtils.php +++ b/src/EcclesiaCRM/utils/GeoUtils.php @@ -56,17 +56,21 @@ public static function getLatLong($address) $logger->debug("Using: Geo Provider - ". $provider->getName()); $geoCoder = new StatefulGeocoder($provider, Bootstrapper::GetCurrentLocale()->getShortLocale()); $result = $geoCoder->geocodeQuery(GeocodeQuery::create($address)); - $logger->debug("We have " . $result->count() . " results"); - if (!empty($result)) { - $firstResult = $result->get(0); - $coordinates = $firstResult->getCoordinates(); - $lat = $coordinates->getLatitude(); - $long = $coordinates->getLongitude(); - } } catch (\Exception $exception) { - $logger->warn("issue creating geoCoder " . $exception->getMessage()); + $logger->debug("issue creating geoCoder " . $exception->getMessage()); + $provider = new Nominatim($adapter, SystemConfig::getValue("sNominatimLink"), SystemConfig::getValue("sChurchEmail") ); + $geoCoder = new StatefulGeocoder($provider, Bootstrapper::GetCurrentLocale()->getShortLocale()); + $result = $geoCoder->geocodeQuery(GeocodeQuery::create($address)); } + $logger->debug("We have " . $result->count() . " results"); + if (!empty($result)) { + $firstResult = $result->get(0); + $coordinates = $firstResult->getCoordinates(); + $lat = $coordinates->getLatitude(); + $long = $coordinates->getLongitude(); + } + return array( 'Latitude' => $lat, 'Longitude' => $long diff --git a/src/skin/js/calendar/GoogleMapEvent.js b/src/skin/js/calendar/GoogleMapEvent.js index 1cefd8f04..c1e37d7c3 100644 --- a/src/skin/js/calendar/GoogleMapEvent.js +++ b/src/skin/js/calendar/GoogleMapEvent.js @@ -21,31 +21,32 @@ if (val.which == 13) { deleteMarker(marker); - var address = $('form #EventLocation').val(); - - $.ajax({ - url:"https://maps.googleapis.com/maps/api/geocode/json?address="+address+"&sensor=false&key="+window.CRM.iGoogleMapKey, - type: "POST", - success:function(res){ + var address = $('form #EventLocation').val(); + + fetch("https://maps.googleapis.com/maps/api/geocode/json?address="+address+"&sensor=false&key="+window.CRM.iGoogleMapKey, { + method: "POST" + }) + .then(resj => resj.json()) + .then(res => { if (res.status == "ZERO_RESULTS") { alert(i18next.t('Wrong address format.')); $('form #EventLocation').val(''); return; } - var latitude = res.results[0].geometry.location.lat; - var longitude = res.results[0].geometry.location.lng; - var EventTitle = $('form #EventTitle').val(); - var EventDesc = $('form #EventDesc').val(); + let latitude = res.results[0].geometry.location.lat; + let longitude = res.results[0].geometry.location.lng; + let EventTitle = $('form #EventTitle').val(); + let EventDesc = $('form #EventDesc').val(); if ( latitude > 0 && longitude > 0 ) { - var Salutation = EventTitle + " ("+EventDesc+")"; - var Name = EventTitle; - var latlng = new google.maps.LatLng(latitude, longitude); + let Salutation = EventTitle + " ("+EventDesc+")"; + let Name = EventTitle; + let latlng = new google.maps.LatLng(latitude, longitude); - var imghref = window.CRM.root+"/v2/calendar"; + let imghref = window.CRM.root+"/v2/calendar"; var iconurl = window.CRM.root+"/skin/icons/event.png"; - var image = { + let image = { url: iconurl, // This marker is 37 pixels wide by 34 pixels high. size: new google.maps.Size(37, 34), @@ -63,8 +64,11 @@ window.CRM.map.setCenter(latlng); } - } - }); + }) + .catch(error => { + // enter your logic for when there is an error (ex. error toast) + console.log(error) + }); } }); diff --git a/src/skin/js/calendar/OpenStreetMapEvent.js b/src/skin/js/calendar/OpenStreetMapEvent.js index 9354779a2..fa3580d36 100644 --- a/src/skin/js/calendar/OpenStreetMapEvent.js +++ b/src/skin/js/calendar/OpenStreetMapEvent.js @@ -21,30 +21,33 @@ var address = $('form #EventLocation').val(); var address_nomatim = address.replace(/ /g,'+'); - - $.ajax({ - url:window.CRM.sNominatimLink+"/search?q="+address_nomatim+"&format=json", - type: "GET", - dataType: "json", - success:function(res){ + + fetch(window.CRM.sNominatimLink+"/search?q="+address_nomatim+"&format=json", { + method: "GET", + headers: { + "Content-Type": "application/json", + } + }) + .then(resj => resj.json()) + .then(res => { if (res === undefined || res.length == 0) { alert(i18next.t('Wrong address format.')); return; } - var latitude = res[0].lat; - var longitude = res[0].lon; - var EventTitle = $('form #EventTitle').val(); - var EventDesc = $('form #EventDesc').val(); + let latitude = res[0].lat; + let longitude = res[0].lon; + let EventTitle = $('form #EventTitle').val(); + let EventDesc = $('form #EventDesc').val(); if ( latitude > 0 && longitude > 0 ) { - var Salutation = EventTitle + " ("+EventDesc+")"; - var Name = EventTitle; + let Salutation = EventTitle + " ("+EventDesc+")"; + let Name = EventTitle; - var imghref = window.CRM.root+"/v2/calendar"; - var iconurl = window.CRM.root+"/skin/icons/event.png"; + let imghref = window.CRM.root+"/v2/calendar"; + let iconurl = window.CRM.root+"/skin/icons/event.png"; - var icon = L.icon({ + let icon = L.icon({ iconUrl: iconurl, iconSize: [32, 32], // size of the icon iconAnchor: [16, 32], // point of the icon which will correspond to marker's location @@ -54,7 +57,7 @@ contentString = "" + Salutation + ""; contentString += "

" + address + "

"; - var centerCard = { + let centerCard = { lat: Number(latitude), lng: Number(longitude)}; @@ -62,8 +65,7 @@ marker = addMarkerWithInfowindow(window.CRM.map, centerCard, icon, Name, contentString); window.CRM.map.setView([centerCard.lat, centerCard.lng], window.CRM.mapZoom); - } - } + } }); } });