<select name="city" id="city" class="glm-left">
<option value="0"></option>
{foreach from=$memberInfo.fieldData.city.list item=v}
- <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
- {$v.name}
- </option>
+ <option value="{$v.value}"{if $v.default} selected="selected"{/if}>{$v.name}</option>
{/foreach}
</select>
</div>
$('#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