La respuesta es simple. A mediados de 2018 Google ha cambiado la forma de utilizar las apis y ahora es necesario agregar un forma de facturación. Osea tu tarjeta de crédito. Pero OpenStreetMap ofrece el servicio de obtener lugares, ciudades, paises , código posta, etc. Buscando por nombre o bien por ubicaciones y todo de forma gratuita. Además ofrece los datos varios formatos como html, xml, json y jsonv2.
En el siguiente ejemplo introduce una ciudad y te devolverá los datos en formato json.
var buscar = $("#txt_post_lugar").val();
$.ajax({ url:'https://nominatim.openstreetmap.org/search/' + buscar + '?format=json&addressdetails=1&limit=1', success: function(data){ $("#pre_post_lugar").html(JSON.stringify(data)); },error : function() { callBack(false); } });
Url : https://nominatim.openstreetmap.org/search/' + buscar + '?format=json&addressdetails=1&limit=1
Parámetros principales:
var lat = $("#txt_post_latitud").val(); var lon = $("#txt_post_longitud").val();
$.ajax({ url:'https://nominatim.openstreetmap.org/reverse?format=json&lat=' + lat + '&lon=' + lon + '&addressdetails=1&limit=1', success: function(data){ $("#pre_post_lugar2").html(JSON.stringify(data)); },error : function() { callBack(false); } });
Url : https://nominatim.openstreetmap.org/reverse?format=json&lat=' + lat + '&lon=' + lon + '&addressdetails=1&limit=1
Parámetros obligatorios: