I am using the Google Maps V3 API. Whenever the user throws a pin onto the street (or perhaps a few meters / yards from the street), he should get the address components that I use to extract from the reset marker.
What bothers me is that when I drop the pin on the street, sometimes it returns the house number / name, when it should always return the list as:
- Street name;
- Town
- State;
- County;
- then Country
I look at the components of the address through custom code that returns the entire JSON response created in the Google Maps API:
getAddress(pinLocation, function(addressobj) { for(i = 0; i < addressobj[0].address_components.length; i++) { var addressComp = addressobj[0].address_components[i].long_name; $('input[type=text][address=comp]:eq(' + i + ')').val(addressComp); } });
Therefore, when data is returned, they return results, and each component of the address (from the list above) each goes to the input field. Here's what the expected result returns:
- San Antonio Valley Rd
(street name) - Livermore
(city) - Diablo range
(state) - Santa Clara
(county) - California
(country)
This is the perfect answer, but from some places, when it falls onto the street (mostly crowded streets), I get the following:
- 2920
(should be Dalarna Ct) - Dalarna Ct
(should be Turlock) - Turlock
(this is okay, but is omitted) - Turlock
(should be Stanislaus) - Stanislav
(should be California)
I do not know how I can create a reliable address component that does not display the house number, and should always return list information (first), because the data always changes when street markers are deleted, when I need it to get the same results as the list.
source share