Answer the question
In order to leave comments, you need to log in
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=АПИ КОД&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>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question