Best API to get zip code by username (US only)?

I have a field for the name of the city that I get (for example, in random order), for example, "NEW YORK", "New York" or "New York" or "Nude".

Having this field value, I need to provide the user with a list of cities that have this value in their name in this format:
NY - New York - 10001
MN - New York Mills - 56567

Efficiency and productivity are important. I can use JavaScript or PHP to get this data.

So far I have been trying to use the Freebase API. Here is an example of the query I used: http://tinyurl.com/3ogpf7k

And here is the JavaScript code I'm using:

// App.q contains city name field value

var query = {
    extended : 1,
    query : [{
        search : App.q,
        type : '/location/citytown',
        id : null,
        name : null,
        postal_codes : [],
        "/location/location/containedby" : [{
            "type" : "/location/us_state",
            "name": null,
            // two letters abbreviation of state
            "/common/topic/alias" : []
        }]
    }]
},
url = 'http://www.freebase.com/api/service/mqlread?callback=?&query=' + 
      encodeURIComponent(JSON.stringify(query));

$.getJSON(url, function( data ) {
    var cities, i, len, name, aliases, j, abbr, postal_code, HTML = [];

    for ( i = 0, len = data.result.length; i < len; i += 1 ) {
        // cities with names matching user input
        if ( data.result[ i ].name.toLowerCase().indexOf( App.q ) === -1 ) continue;
        // cities that have postal_codes data available
        if ( data.result[ i ].postal_codes.length === 0 ) continue;

        name = data.result[ i ].name;
        aliases = data.result[ i ]["/location/location/containedby"][0]["/common/topic/alias"];
        postal_code = data.result[ i ].postal_codes[0];

        // find two-letters alias
        for ( j = aliases.length - 1; j >= 0; j -= 1 ) {
            if ( aliases[j].length === 2 && aliases[j] === aliases[j].toUpperCase() ) {
                 abbr = aliases[j];
            }
        }

        HTML.push( D.renderHTML( liTemplate, {
            name : name,
            abbr : abbr,
            postal_code : postal_code
        }) );

    }

    console.log( HTML.join('') );
});

"-", , "- ".

API, ? - API Freebase?

UPD. API, - ( , - ):
: http://www.geonames.org/export/web-services.html
: http://api.geonames.org/postalCodeSearch?placename=los%20angeles&username=demo&maxRows=500

!

+3
1

. , MQL "", "name".

, ( , , , ). , this, :

"search":       {"query":"New York","score":null,"type_strict":"all"},
"sort":"-search.score",
"type":"/location/citytown",

"", "". mql_filter , , ( ).

,

+1

All Articles