Quick filter location by distance

Use a simple javascript to play with map coordinates and show/hide place by a max distance from the searched position
Enter a location, all the cities listed below are at most 150km from the point you are looking for
48.856614
2.3522219
25.2048493
55.2707828
40.852393087071
14.269129290527
				
					<script>
var km_max = 150;
var autocomplete;
var url = window.location.pathname;
jQuery(window).on('load', function() {
  addressField = document.querySelector("#form-field-address");
  autocomplete = new google.maps.places.Autocomplete(addressField, {
    types: ["address"],
  });
  autocomplete.addListener("place_changed", function(){
    const place = autocomplete.getPlace();
    var lat = place.geometry.location.lat();
    var lng = place.geometry.location.lng();
    jQuery('.elementor-widget-e-query-posts article').each(function(){
      let slng = jQuery(this).find('.longitude').text();
      let slat = jQuery(this).find('.latitude').text();
      let name = jQuery(this).find('h2').text();
      let distanza = coordinate_distance(lat, lng, slat, slng);
      console.log(name+' distante '+distanza+' km');
      if (km_max > distanza) {
        jQuery(this).show();
      } else {
        jQuery(this).hide();
      }
    });
    
  });
});

function coordinate_distance(lat1, lon1, lat2, lon2) {
  var p = 0.017453292519943295;    // Math.PI / 180
  var c = Math.cos;
  var a = 0.5 - c((lat2 - lat1) * p)/2 + 
          c(lat1 * p) * c(lat2 * p) * 
          (1 - c((lon2 - lon1) * p))/2;
  return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
}
</script>