Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the address field with moved marker #11

Open
renooble opened this issue May 3, 2012 · 4 comments
Open

Update the address field with moved marker #11

renooble opened this issue May 3, 2012 · 4 comments

Comments

@renooble
Copy link

renooble commented May 3, 2012

How can I update the address field, when the user moved the marker?
Wasn't this feature part of an earlier version? When I try at http://xilinus.com/jquery-addresspicker/demos/ the lat and lng fields will be updated, but not the address field.

Is there a good way to do it since at that stage google already returned the geocoding information?

Thank you for your answer.

@sgruhier
Copy link
Owner

sgruhier commented May 3, 2012

in fact I just update lat/lng that I get from marker position
but you're right, I could request to google addresses at that location.
But it can return more than one address, how do you want to handle that?

@renooble
Copy link
Author

renooble commented May 3, 2012

Hi sgruhier,

If the user changes the marker position, the variation of multiple addresses should be limited. It won't give you returns in multiple cities or even countries, like when you enter e.g. "melbourne" in the address field (would return a city in Florida and Australia). Since the results are locally limited, I would suggest just to display the first address in the google map response.

Is that possible?

@sgruhier
Copy link
Owner

sgruhier commented May 5, 2012

display it in autocomplete suggestions?
I think if you change address textfield this could be confusing for the user.

@dexstar
Copy link

dexstar commented May 14, 2012

I'm stuck at this point. All I try to do is to get the information about the town and the country in the fields left. I only need these fields to rarely address my users positions (they could enter it thierselves, but only lat, long, town and country is needed).

Could you fix this or just give me a hint how to do it?

_updatePosition seems to update only lat and long, even if I read out the ther tags from google.

here is my try:

    _updatePosition: function(location) {
      if (this.lat) {
        this.lat.val(location.lat());
      }
      if (this.lng) {
        this.lng.val(location.lng());
      }
      this.geocoder.geocode({'latLng': location}, function(results, status){
     if (status == google.maps.GeocoderStatus.OK) {
      //console.log(results);

      if (this.locality) {
      this.locality.val(this._findInfo(results[1], 'locality'));
      }

        if (results[1]) {
        var indice=0;
        for (var j=0; j<results.length; j++)
        {
            if (results[j].types[0]=='locality')
                {
                    indice=j;
                    break;
                }
            }
        //alert('The good number is: '+j);
        console.log(results[j]);
        for (var i=0; i<results[j].address_components.length; i++)
            {
                if (results[j].address_components[i].types[0] == "locality") {
                        //this is the object you are looking for
                        city = results[j].address_components[i];
                    }
                if (results[j].address_components[i].types[0] == "administrative_area_level_1") {
                        //this is the object you are looking for
                        region = results[j].address_components[i];
                    }
                if (results[j].address_components[i].types[0] == "country") {
                        //this is the object you are looking for
                        country = results[j].address_components[i];
                    }
            }

            //city data
            alert(city.long_name + " || " + region.long_name + " || " + country.long_name)
            //this.locality.val(city.long_name);

            } else {
              alert("No results found");
            }
        //}
      } else {
        alert("Geocoder failed due to: " + status);
      }

      });
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants