Zurück

Switzerland city, canton, zip search - free api access Share:

For projects with Switzerland cities, cantons, zip codes with search or autocomplete feature

On immocosmos.ch we are using API to access data in autocomplete on front of website. It is free if you have less then 20 000 requests per day.

If you need more please send us email to support@immocosmos.ch.


A) For city only without cantons and zip codes:

URL: https://www.immocosmos.ch/api/geo?city_only=


response JSON :

[{"Name":"","Type":"","TypeLabel":""}]


B) For city/cantons/zip codes:

URL: https://www.immocosmos.ch/api/geo?city=


return JSON :

[{"Name":"","Type":"","TypeLabel":""}]


C) For all of data without any query on database:

URL: https://www.immocosmos.ch/api/geo


response JSON :

[{"Name":"","Type":"","TypeLabel":""}]


URL's A) and B) support accents. You can have one or more letters in query parameter. 


EXAMPLE

https://www.immocosmos.ch/api/geo?city=Zürich will return JSON:

[{"Name":"Zürich","Type":"canton","TypeLabel":"Kanton"},{"Name":"Zurich","Type":"place","TypeLabel":"Ort"},{"Name":"Zürich","Type":"place","TypeLabel":"Ort"}]


Complete javascript example with http://easyautocomplete.com lib:

var options = {

    minCharNumber: 3,

    url: function(phrase) {
        return "https://www.immocosmos.ch/api/geo?city=" + phrase;
    },

    getValue: function(element) {

        return element.Name+ ", "+element.TypeLabel;
    },

    list: {
        match: {
            enabled: false
        },
        onSelectItemEvent: function() {
            var item = $("#location").getSelectedItemData();
            console.log(item)
        }

    },

    theme: "square"
};

$("#location").easyAutocomplete(options);


Happy coding :)