Announcement

Collapse
No announcement yet.

Google Autocomplete

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Google Autocomplete

    I put a ticket in on this, but just in case someone has had the issue...

    I setup Google Autocomplete for the addresses. It works great EXCEPT it is only pulling Canadian and Australian addresses and not USA at all. We do ship to those countries, but very rarely.

    Any thoughts on what I screwed up?

    Thanks,

    DaveW

  • #2
    same thing here , not pulling any addresses ... API loaded , enabled ... google console state no any API call from site .. weird ..

    Comment


    • #3
      kalaja If you have a modified checkout page, then you need to add in the new code.


      Code:
      <!--START: GOOGLE_AUTOFILL-->
      <script>
          var placeSearch, autocomplete;
          var componentForm = {
              street_number: 'short_name',
              route: 'long_name',
              locality: 'long_name',
              administrative_area_level_1: 'short_name',
              country: 'long_name',
              postal_code: 'short_name'
          };
      
          function initAutocomplete() {
      
              var countries = [];
              var lastCountry = "";
              jQuery('#billing_country > option').each(function () {
                  countries.push(jQuery(this).attr('value').toLowerCase());
                  lastCountry = jQuery(this).attr('value').toLowerCase();
              });
              if (countries.length < 2) countries = lastCountry;
      
              autocomplete = new google.maps.places.Autocomplete(
                  (document.getElementById('billing_address')),
                  {types: ['geocode']});
              autocomplete.addListener('place_changed', fillInAddressBilling);
              autocomplete.setComponentRestrictions({'country': countries});
      
              autocomplete2 = new google.maps.places.Autocomplete(
                  (document.getElementById('shipping_address')),
                  {types: ['geocode']});
              autocomplete2.addListener('place_changed', fillInAddressShipping);
              autocomplete2.setComponentRestrictions({'country': countries});
          }
      
          function fillInAddressShipping() {
              // Get the place details from the autocomplete object.
              var place = autocomplete2.getPlace();
      
              var address, address2, city, country, state, zip = '';;
      
              for (var i = 0; i < place.address_components.length; i++) {
                  var addressType = place.address_components[i].types[0];
      
                  if(addressType == 'street_number') address = place.address_components[i].long_name;
                  if(addressType == 'route') address2 = place.address_components[i].short_name;
                  if(addressType == 'locality') city = place.address_components[i].long_name;
                  if(addressType == 'country') country = place.address_components[i].short_name;
                  if(addressType == 'administrative_area_level_1') state = place.address_components[i].short_name;
                  if(addressType == 'postal_code') zip = place.address_components[i].long_name;
              }
      
      
              var addressItems = place.address_components;
      
              if(address && address2) jQuery('#shipping_address').val(address + ' ' + address2);
              else if (address == 'undefined') jQuery('#shipping_address').val(address + ' ' + address2);
              else jQuery('#shipping_address').val(address2);
      
              jQuery('#shipping_city').val(city);
              jQuery('#shipping_country').val(country);
              populateState('shipping_state', 'shipping_country', '', true, 'State'); check_stateValidator('shipping'); 
              jQuery('#shipping_state').val(state);
              jQuery('#shipping_zip').val(zip);
      
              check_address('shipping');
          }
      
          function fillInAddressBilling() {
              // Get the place details from the autocomplete object.
              var place = autocomplete.getPlace();
      
              var address, address2, city, country, state, zip = '';;
      
              for (var i = 0; i < place.address_components.length; i++) {
                  var addressType = place.address_components[i].types[0];
      
                  if(addressType == 'street_number') address = place.address_components[i].long_name;
                  if(addressType == 'route') address2 = place.address_components[i].short_name;
                  if(addressType == 'locality') city = place.address_components[i].long_name;
                  if(addressType == 'country') country = place.address_components[i].short_name;
                  if(addressType == 'administrative_area_level_1') state = place.address_components[i].short_name;
                  if(addressType == 'postal_code') zip = place.address_components[i].long_name;
              }
      
              var addressItems = place.address_components;
      
              if(address && address2) jQuery('#billing_address').val(address + ' ' + address2);
              else if (address == 'undefined') jQuery('#billing_address').val(address + ' ' + address2);
              else jQuery('#billing_address').val(address2);
              jQuery('#billing_city').val(city);
              jQuery('#billing_country').val(country);
              populateState('billing_state', 'billing_country', '', true, 'State'); check_stateValidator('billing'); 
              jQuery('#billing_state').val(state);
              jQuery('#billing_zip').val(zip);
      
              check_address('billing');
          }
      
          // Bias the autocomplete object to the user's geographical location,
          // as supplied by the browser's 'navigator.geolocation' object.
          function geolocate() {
              if (navigator.geolocation) {
                  navigator.geolocation.getCurrentPosition(function(position) {
                  var geolocation = {
                      lat: position.coords.latitude,
                      lng: position.coords.longitude
                  };
                  var circle = new google.maps.Circle({
                      center: geolocation,
                      radius: position.coords.accuracy
                  });
                  autocomplete.setBounds(circle.getBounds());
                  });
              }
          }
      </script>
      <script src="https://maps.googleapis.com/maps/api/js?key=[googleaddress_api]&libraries=places&callback=initAutocomplete" async defer></script>
      <!--END: GOOGLE_AUTOFILL-->

      Comment


      • #4
        Thanks JoeBTI I did modified shipping display options ( now this feature is standard ) ... It's working now except it's showing any other country but USA ... LOL... we have so many customers in Algeria.... what I'm doing wrong ? Just curios why support will not provide code or any info what to do ....
        Last edited by kalaja; 03-29-2019, 08:51 AM.

        Comment


        • #5
          Works fine for me, however I only have US and Canada as country options. Something is going wacky... I would definitely send them a ticket since two of you have the same issue.

          Comment


          • #6
            I would open ticket if I can access admin page ... this update suck ... 3 min to load admin page ..

            Comment


            • #7
              Just email [email protected] it automatically creates a ticket.

              Comment


              • #8
                decided to turn it off .. complete mess , now entire world has free shipping beside we have domestic only checked ..had to cancel orders, of course lot of nasty emails from customers... great weekend..

                Comment


                • #9
                  I put a ticket in and have not heard anything.
                  DaveW

                  Comment


                  • #10
                    JoeBTI is there any specific settings that should be changed in google console to pull USA addresses , mine now pulling only countries starting with A ..Albania, Afghanistan, Algeria , etc..or issue is with 3dcart module itself?

                    Comment


                    • #11
                      No, all I did was create a places api, restricted the key to my site and created a billing account. Probably an issue with 3d...

                      Comment


                      • #12
                        THey have elevated my ticket to the developers.

                        DaveW

                        Comment


                        • #13
                          Where should this code go? We did pay 3DCart for doing out check out page, so I assume that is why it is not working.
                          http://www.pack-secure.com

                          Packaging and Shipping Supply Specialists

                          Comment


                          • #14
                            At the bottom of checkout-singlepage.html.

                            Comment


                            • #15
                              any updates on this ... or this will stay feature on paper only , unusable ..

                              Comment

                              Working...
                              X