Pregunta

Intento encontrar un archivo XML que pueda usar en lugar de una tabla de base de datos de búsqueda hasta que cambiemos nuestro alojamiento web a la base de datos correcta.

¿Alguien puede referirme a un archivo XML con elementos cuyos hijos tengan códigos postales, estados y ciudades? Por ejemplo:

<zip code="98117">
    <state>WA</state>
    <city>Seattle</state>
</zip>

O

<entry>
    <zip>98117</zip>
    <state>WA</state>
    <city>Seattle</city>
</entry>

Usaré LINQ en C # para consultar estos datos.

¿Fue útil?

Solución

Echa un vistazo a este, proporciona varios diferentes gratis.

https://stackoverflow.com/questions/24471/zip-code-database

Otros consejos

Hay una base de datos de código postal gratuita ubicada en:

http://www.populardata.com

Creo que es un archivo .CSV pero puede convertirlo en un archivo XML con bastante facilidad.

Aquí hay un código para hacer el autocompletado city.state basado en un código postal ingresado.

<script type="text/javascript">//<![CDATA[
$(function() {
    // IMPORTANT: Fill in your client key
    var clientKey = "js-9qZHzu2Flc59Eq5rx10JdKERovBlJp3TQ3ApyC4TOa3tA8U7aVRnFwf41RpLgtE7";

    var cache = {};
    var container = $("#example1");
    var errorDiv = container.find("div.text-error");

    /** Handle successful response */
    function handleResp(data)
    {
        // Check for error
        if (data.error_msg)
            errorDiv.text(data.error_msg);
        else if ("city" in data)
        {
            // Set city and state
            container.find("input[name='city']").val(data.city);
            container.find("input[name='state']").val(data.state);
        }
    }

    // Set up event handlers
    container.find("input[name='zipcode']").on("keyup change", function() {
        // Get zip code
        var zipcode = $(this).val().substring(0, 5);
        if (zipcode.length == 5 && /^[0-9]+$/.test(zipcode))
        {
            // Clear error
            errorDiv.empty();

            // Check cache
            if (zipcode in cache)
            {
                handleResp(cache[zipcode]);
            }
            else
            {
                // Build url
                var url = "http://www.zipcodeapi.com/rest/"+clientKey+"/info.json/" + zipcode + "/radians";

                // Make AJAX request
                $.ajax({
                    "url": url,
                    "dataType": "json"
                }).done(function(data) {
                    handleResp(data);

                    // Store in cache
                    cache[zipcode] = data;
                }).fail(function(data) {
                    if (data.responseText && (json = $.parseJSON(data.responseText)))
                    {
                        // Store in cache
                        cache[zipcode] = json;

                        // Check for error
                        if (json.error_msg)
                            errorDiv.text(json.error_msg);
                    }
                    else
                        errorDiv.text('Request failed.');
                });
            }
        }
    }).trigger("change");
});

//]] >

Aquí está la API: http://www.zipcodeapi.com/Examples#example1 .

Puede solicitar el contenido en XML a través de Para recuperar los datos directamente en XML, puede usar .xml en el formato de la solicitud.

https://www.zipcodeapi.com/rest/RbdapNcxbjoCvfCv4N5iwB3L4beZg017bfiB2u9eOxQkMtQQgV9NxdyCoNCENDMZ/ info.xml / 90210 / grados

Responderá con

<response>
   <zip_code>90210</zip_code>
   <lat>34.100501</lat>
   <lng>-118.414908</lng>
   <city>Beverly Hills</city>
   <state>CA</state>
   <timezone>
   <timezone_identifier>America/Los_Angeles</timezone_identifier>
   <timezone_abbr>PDT</timezone_abbr>
      <utc_offset_sec>-25200</utc_offset_sec>
      <is_dst>T</is_dst>
   </timezone>
   <acceptable_city_names/>
</response>

Los documentos de la API están en https://www.zipcodeapi.com/API

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top