Updating the geocode for city issue
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 30 Aug 2018 12:47:56 +0000 (08:47 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 30 Aug 2018 12:47:56 +0000 (08:47 -0400)
City field is being sent over to geocoder with huge amounts of untrimed
spaces.

views/admin/events/edit.html

index 07e07c3..ed0a62d 100755 (executable)
                 {foreach $event.fieldRequired as $fieldName => $fValue}
                     {if $fieldName != 'status' && $fieldName != 'descr' && $fieldName != 'name_slug'}
                 if ( {if $fValue}true{else}false{/if} ) {
-                    console.log('{$fieldName}', $('input[name="{$fieldName}"]'));
-                    console.log('{$fieldName}.val()', $('input[name="{$fieldName}"]').val());
+                    // console.log('{$fieldName}', $('input[name="{$fieldName}"]'));
+                    // console.log('{$fieldName}.val()', $('input[name="{$fieldName}"]').val());
                     if ( !$('input[name="{$fieldName}"]').val() ) {
                         formErrors.push('{$fieldName}');
                     }
                     {else if $fieldName == 'descr'}
                 if ( {if $fValue}true{else}false{/if} ) {
                     descr = get_tinymce_content();
-                    console.log( 'descr', descr );
+                    // console.log( 'descr', descr );
                     if ( !descr ) {
                         formErrors.push('{$fieldName}');
                     }
                 {/foreach}
                 var numErrors = formErrors.length;
                 if ( numErrors > 0 ) {
-                    console.log('formErrors: ', formErrors);
+                    // console.log('formErrors: ', formErrors);
                     var msg = "The following fields are required for this Event:\n";
                     for ( var i = 0; i < numErrors; i++ ) {
                         msg += formErrors[i] + "\n";
             {if $settings.selected_map_interface == 1}
 
                 var nominatimAPI = "https://nominatim.openstreetmap.org/search/";
-            
+
                 /*
                  *  Leaflet Map
                  *  API reference: https://leafletjs.com/reference-1.3.2.html
                  */
                 function initMap(locID) {
 
-                    console.log( 'locID: ', locID );
+                    // console.log( 'locID: ', locID );
 
                     // Set default - Need to make this configurable
                     var startLat = $('#glmLat_' + locID).val();
                     $('#glm-estimate-location_' + locID).on('click', function() {
 
                         var addrStreet = $('#address_' + locID).val();
-                        var addrCity = $('#city_' + locID + ' option:selected').text();
+                        var addrCity = $('#city_' + locID + ' option:selected').text().trim();
                         var addrState = $('#state_' + locID).val();
                         var addrCountry = $('#country_' + locID).val();
                         var addrZip = $('#zip_' + locID).val();
                             postalcode: addrZip
                         })
                         .fail(function(data) {
-                            alert('Sorry, we were unable to get a location from the above address.');                        
+                            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 = Number(data[0].lat);
                                 glmLng = Number(data[0].lon);
                                 $('#glmLat_' + locID).val(glmLat.toFixed(6));
                                 $('#glmLng_' + locID).val(glmLng.toFixed(6));
-                                    
+
                                 // Move map pointer to the proper location
                                 leafletMarker.setLatLng(new L.LatLng(glmLat, glmLng),{ draggable:'true' });
                                 map[locID].panTo(new L.LatLng(glmLat, glmLng));
 
                             }
 
-                        });         
+                        });
 
                     });
 
                 }
 
                 function glmGeocode(locID) {
-    
+
                     // Get all address parts
                     var geoAddr1 = $('#address_' + locID ).val().trim();
                     var geoAddr2 = '';  // $('#addr2').val().trim();
                     var geoState = $('#state_' + locID).val();
                     var geoZIP = $('#zip_' + locID).val().trim();
                     var geoCountry = $('#country_' + locID).find('option:selected').text().trim();
-    
+
                     // Assemble address string for
                     var geoAddress = geoAddr1 + ', ' + geoAddr2 + ', ' + geoCity + ', ' + geoState + ' ' + geoZIP + ', ' + geoCountry;
-    
+
                     // Send to Google Geocoder
                     geocoder[locID].geocode( { 'address': geoAddress }, function(results, status) {
-    
+
                         // If we have a geocode solution
                         if (status == google.maps.GeocoderStatus.OK) {
-    
+
                             // Center the map and locate the marger to the new location
                             map[locID].setCenter(results[0].geometry.location);
                             marker[locID].setPosition( results[0].geometry.location );
-    
+
                             // Assign the new position to the hidden fields for submission
                             glmLat = results[0].geometry.location.lat();
                             glmLng = results[0].geometry.location.lng();
                             $('#glmLat_' + locID).val(glmLat.toFixed(6));
                             $('#glmLng_' + locID).val(glmLng.toFixed(6));
-    
+
                             // Also display it to the user
                             $('#mapPosition_' + locID).html('Lat ' + glmLat.toFixed(4) + ', Lon ' + glmLng.toFixed(4));
-    
+
                             // Otherwise tell the user.
                         } else {
                             alert('Not able to estimate map position from the current address.');
                         }
                     });
-    
-    
+
+
                 }
 
             {/if}
-                
+
             /*
              * Misc support items
              */