public getUrl()

in src/geocoder/geocoder.ts [278:331]


        public getUrl(): string {
            let parameters: _.Dictionary<string> = {
                key: Settings.BingKey,
            };

            let entityType: string = this.getBingEntity();
            let queryAdded: boolean = false;
            if (entityType) {
                if (entityType === BingEntities.Postcode) {
                    parameters["includeEntityTypes"] = "Postcode,Postcode1,Postcode2,Postcode3,Postcode4";
                }
                else if (this.query.indexOf(",") === -1 && (entityType === BingEntities.AdminDivision1 || entityType === BingEntities.AdminDivision2)) {
                    queryAdded = true;
                    try {
                        parameters["adminDistrict"] = decodeURIComponent(this.query);
                    } catch (e) {
                        return null;
                    }
                }
                else {
                    parameters["includeEntityTypes"] = entityType;

                    if (this.query.length === 2 && entityType === BingEntities.Sovereign) {
                        queryAdded = true;
                        try {
                            parameters["countryRegion"] = decodeURIComponent(this.query);
                        } catch (e) {
                            return null;
                        }
                    }
                }
            }

            if (!queryAdded) {
                try {
                    parameters["q"] = decodeURIComponent(this.query);
                } catch (e) {
                    return null;
                }
            }

            let cultureName: string = navigator["userLanguage"] || navigator["language"];
            cultureName = mapLocalesForBing(cultureName);
            if (cultureName) {
                parameters["c"] = cultureName;
            }
            parameters["maxRes"] = "20";
            // If the query is of length 2, request the ISO 2-letter country code to be returned with the result to be compared against the query so that such results can be preferred.
            if (this.query.length === 2 && this.category === CategoryTypes.CountryRegion) {
                parameters["include"] = "ciso2";
            }

            return UrlUtils.setQueryParameters(this.bingGeocodingUrl, parameters, /*keepExisting*/true);
        }