K
K
Kanare2020-10-20 15:36:28
JavaScript
Kanare, 2020-10-20 15:36:28

Trouble setting up Google Maps API?

I found a manual on the Internet for requesting client geodata for setting up an order

https://netrange.ru/webdev/woocommerce-dostavra.html

Created an API added to the code on the page

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=АПИ КОД&amp;sensor=false"></script>
<script type="text/javascript">
var geocoder;
function initialize() {
  geocoder = new google.maps.Geocoder();
}
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    var pos = {
      lat: position.coords.latitude,
      lng: position.coords.longitude
    };
    console.log('your lat:'+position.coords.latitude+'your lon:'+position.coords.longitude);
    geocoder.geocode( {'location': pos}, function(results, status) {
      if (status == 'OK') {
        var db_obj = results[0].address_components;
        var route ='';
        var street_number='';
        jQuery.each(db_obj, function(i) {
          if (this.types=='route'){
            route = this.long_name;
          }
          if (this.types=='street_number'){
            street_number = this.long_name;
          }
        });
        var address = route+street_number;
        console.log('your address: '+address);
        if (address!=''){
          jQuery('#shipping_address_1').val(route+' '+street_number);
          jQuery('#shipping_address_1').change();
        }
      }
    });
  });
}
function codeAddress() {
  var address = 'Узбекистан, Ташкенсткая область, Ташкент, '+jQuery('#shipping_address_1').val();
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == 'OK') {
      var db_obj = results[0].address_components;
      jQuery.each(db_obj, function(i) {
        if (this.types=='postal_code'){
          console.log('your postal_code:'+this.long_name);
          jQuery('#shipping_postcode').val(this.long_name);
          jQuery('body').trigger('update_checkout');
        }
      });
    }else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });
}
jQuery(document).ready(function(){
  initialize();
  jQuery('#shipping_address_1').change(function(){
    codeAddress();
  });
});
</script>


When checking in the console, it writes

util. js:229 Google Maps JavaScript API warning: SensorNotRequired https://developers.google.com/maps/documentation/j...
Nz.o @ util.js:229
(anonymous) @ js?key=API CODE&sensor=false: 140
Promise.then (async)
(anonymous) @ js?key=API&sensor=false:140
setTimeout (async)
Jj @ js?key=API&sensor=false:140
google.maps.Load @ js?key=API&sensor= false:14
(anonymous) @ js?key=API CODE&sensor=false:258
(anonymous) @ js?key=API CODE&sensor=false:258

How can I fix it Please tell me in the documentation I'm starting to read the errors I didn't find anything

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-10-20
@Kanare

I'll quote the documentation for you, since you couldn't open it.

The sensor parameter is no longer required for the Maps JavaScript API. It won't prevent the Maps JavaScript API from working correctly, but we recommend that you remove the sensor parameter from the script element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question