From ff3a865692d651f93e5b5358846ed2810ab96545 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Mon, 27 Aug 2018 13:53:27 -0400 Subject: [PATCH] Changed to using OpenStreetMaps Nominatim for geolocation services whe using Leaflet for maps. --- views/admin/member/memberInfo.html | 2 - .../member/memberInfo/editProfileAddress.html | 65 ++++++++++--------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/views/admin/member/memberInfo.html b/views/admin/member/memberInfo.html index c9001d2d..31e3894d 100755 --- a/views/admin/member/memberInfo.html +++ b/views/admin/member/memberInfo.html @@ -3,8 +3,6 @@ {if $settings.selected_map_interface == 1} - - {/if} {if $settings.selected_map_interface == 2} diff --git a/views/admin/member/memberInfo/editProfileAddress.html b/views/admin/member/memberInfo/editProfileAddress.html index 6ca6a21d..37de80d3 100755 --- a/views/admin/member/memberInfo/editProfileAddress.html +++ b/views/admin/member/memberInfo/editProfileAddress.html @@ -43,9 +43,7 @@ @@ -197,46 +195,49 @@ $('#glmLng').val(position.lng.toFixed(6)); }); - - - // Temporarily use Google geolocation till we have our own geolocation server - // When estimate location button is clicked, geocode using address + /* + * Use OpenStreetMaps Nominatim for Geolocation + */ + var nominatimAPI = "https://nominatim.openstreetmap.org/search/"; $(document).on('click','#glm-estimate-location', function() { - var geocoder = new google.maps.Geocoder(); - - // Get all address parts - var geoAddr1 = $('#addr1').val().trim(); - var geoAddr2 = $('#addr2').val().trim(); - var geoCity = $('#city').find('option:selected').text().trim(); - var geoState = $('#state').find('option:selected').text().trim(); - var geoZIP = $('#zip').val().trim(); - var geoCountry = $('#country').find('option:selected').text().trim(); - - // Assemble address string for - var geoAddress = geoAddr1 + ', ' + geoAddr2 + ', ' + geoCity + ', ' + geoState + ' ' + geoZIP + ', ' + geoCountry; - - // Send to Google Geocoder - geocoder.geocode( { 'address': geoAddress }, function(results, status) { - - // If we have a geocode solution - if (status == google.maps.GeocoderStatus.OK) { - + var addrStreet = $('#addr1').val(); + var addrCity = $('#city option:selected').text(); + var addrState = $('#state').val(); + var addrCountry = $('#country').val(); + var addrZip = $('#zip').val(); + + var location = $.getJSON( nominatimAPI, { + format: 'json', + street: addrStreet, + city: addrCity, + state: addrState, + country: addrCountry, + postalcode: addrZip + }) + .fail(function(data) { + alert('Sorry, we were unable to get a location from the above address.'); + }) + .done(function( data ) { + + if( !data[0] || !data[0].lat || !data[0].lon ) { + alert('Sorry, we were unable to get a location from the above address.'); + } else { + // Assign the new position to the hidden fields for submission - glmLat = results[0].geometry.location.lat(); - glmLng = results[0].geometry.location.lng(); + glmLat = Number(data[0].lat); + glmLng = Number(data[0].lon); $('#glmLat').val(glmLat.toFixed(6)); $('#glmLng').val(glmLng.toFixed(6)); + // Move map pointer to the proper location leafletMarker.setLatLng(new L.LatLng(glmLat, glmLng),{ draggable:'true' }); leafletMap.panTo(new L.LatLng(glmLat, glmLng)); - // Otherwise tell the user. - } else { - alert('Not able to estimate position from the current address.'); } - }); + }); + }); // Recenter when Update Poineter after entering Lat/Lon is clicked -- 2.17.1