Code Monkey home page Code Monkey logo

Comments (12)

sgruhier avatar sgruhier commented on August 31, 2024

I dont think you can with google geocoder
If you find a solution please share

from jquery-addresspicker.

dggit avatar dggit commented on August 31, 2024

you have to filter the results in _geocode function
you iterate in result object in order to find type=="country" & shortname==your country code and you only take the one that met this condition

here is my modified function for france adresses, it is a bit dirty but it works

// Autocomplete source method: fill its suggests with google geocoder results
    _geocode: function(request, response) {
        var address = request.term, self = this;
        this.geocoder.geocode({
            'address': address + this.options.appendAddressString,
            'region': this.options.regionBias
        }, function(results, status) {
            var fr_results= [];
            if (status == google.maps.GeocoderStatus.OK) {
                for (var i = 0; i < results.length; i++) {
                    results[i].label =  results[i].formatted_address;
                    for (var j = 0; j<results[i].address_components.length; j++)
                    {   
                        //console.log(results[i]);
                        if ((results[i].address_components[j].types[0] =="country") && (results[i].address_components[j].short_name =="FR"))
                        {
                            //console.log(results[i].address_components[j].short_name);
                            results[i].label =  results[i].formatted_address;
                            //fr_results[i] = results[i];
                            fr_results.push(results[i]);
                        }
                    }
                };
            } 
            //console.log(results);
            //console.log(fr_results);
            response(fr_results);
        })
    },

from jquery-addresspicker.

leccy avatar leccy commented on August 31, 2024

This is great! But how do I get this to work for UK area? I changed the short_name to UK and GB and can see nothing else in the code that would require to be changed. I've tried other short country names but nothing works except France... am I missing something obvious?

from jquery-addresspicker.

leccy avatar leccy commented on August 31, 2024

I changed the entry to GB over a week ago which produced no results but it seems to be working now. Seems it didn't work instantly but can't understand why :/

from jquery-addresspicker.

xurei avatar xurei commented on August 31, 2024

I made a fork that supports this feature : https://github.com/xurei/jquery-addresspicker

Usage :
$( 'input[name="address"]' ).addresspicker({
...,
componentsFilter: 'country:BE',
});

from jquery-addresspicker.

sgruhier avatar sgruhier commented on August 31, 2024

you should submit a pull request

from jquery-addresspicker.

xurei avatar xurei commented on August 31, 2024

Done already ;-)

from jquery-addresspicker.

hugomaiavieira avatar hugomaiavieira commented on August 31, 2024

@sgruhier 👍 for this feature. I need.

Is @xurei pull request not ok to be merged?

from jquery-addresspicker.

sgruhier avatar sgruhier commented on August 31, 2024

I'll do it this week-end
But I can't just merge the PR because code has changed since then and I found few bugs.
But I'll use @Xurel code and do it.

from jquery-addresspicker.

hugomaiavieira avatar hugomaiavieira commented on August 31, 2024

@sgruhier mercy! 😄

from jquery-addresspicker.

xurei avatar xurei commented on August 31, 2024

@hugomaiavieira yes, it's okay to be merged :-)

from jquery-addresspicker.

MichaelBrauner avatar MichaelBrauner commented on August 31, 2024

Is it possible to do something like this:

"componentsFilter": "type:geocode",

?

from jquery-addresspicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.