This is an offshoot of https://www.drupal.org/node/1129512 which integrates with geofield for storage. It would be nice to allow the address to be created and stored using the Addressfield module.

I've created a patch that does that integration. Currently its pretty straight forward. If the Addressfield module is installed it adds a checkbox and selection for using the Addressfield in your field settings. For the user it adds an additional button for using the designated Addressfield to map the location.

I left the current field as an optional field to use to get a mapped location.

Comments

jlockhart’s picture

StatusFileSize
new7.38 KB

the patch

jlockhart’s picture

Status: Active » Needs review
valeraye’s picture

Very good !
Thanks for this.

I would add some lines in geolocation_googlemaps_widget.js to fill the address field when the marker is moved on the map.

In the Drupal.geolocation.codeLatLng function :

    if ((op == 'marker' || op == 'geocoder') && geocoder) {
      geocoder.geocode({'latLng': latLng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          $('#geolocation-address-' + i + ' input').val(results[0].formatted_address);
					var addressfield = $('#geolocation-addressfield-geocode-' + i).attr('addressfield');

					// get the values from the addressfield fields
		      $("input[name='"+addressfield+"[und][0][thoroughfare]'").val(results[0].address_components[0].long_name + ' ' +results[0].address_components[1].long_name);
		      //$("input[name='"+addressfield+"[und][0][premise]'").val();
		      $("input[name='"+addressfield+"[und][0][locality]'").val(results[0].address_components[2].long_name);
		      $("select[name='"+addressfield+"[und][0][administrative_area]'").val();
		      $("input[name='"+addressfield+"[und][0][postal_code]'").val(results[0].address_components[6].long_name);
          
          if (op == 'geocoder') {
            Drupal.geolocation.setZoom(i, results[0].geometry.location_type);
          }
        }
        else {
          $('#geolocation-address-' + i + ' input').val('');
          if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
            alert(Drupal.t('Geocoder failed due to: ') + status);
          }
        }
      });
mtoscano’s picture

Hi,
the patch works fine with the latest dev, but only on desktop. On mobile the button Get Location from Address doesn't produce any effect.
valeraye code to update Address also works only on standard browser, any idea?

mtoscano’s picture

valeraye code works just for small adjustment, as it doesn't update administrative area (county/province) postal code or country

derjochenmeyer’s picture

Status: Needs review » Needs work

@mato, valeraye: could you share an updated patch? :)

christianadamski’s picture

Component: Google Maps geolocation » Geolocation Field / Backend
Status: Needs work » Closed (won't fix)

Closing all 7.x issues. It's time.