I'm using Google Maps V3 API. Whenever a user drops a pin on a street (or perhaps a few metres/yards away from a street) it should get the address components which I use to retrieve from the dropped marker.
What is bothering me, is that when I drop a pin on a street, sometimes it returns the house number/name when it should always return the list as:
- Street name;
- City;
- State;
- County;
- then Country
I go through the address components via a custom made that returns the entire JSON response generated from 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);
}
});
So when the data is returned it returns results and each address component (from the list above) each goes into a input field. This is what kind of expected results returns:
- San Antonio Valley Rd
(street name)
- Livermore
(city)
- Diablo Range
(state)
- Santa Clara
(county)
- California
(country)
This is the perfect response but from some locations when dropping on a street (mostly crowded streets) I get like:
- 2920
(should be Dalarna Ct)
- Dalarna Ct
(should be Turlock)
- Turlock
(this is okay, but is omitted)
- Turlock
(should be Stanislaus)
- Stanislaus
(should be California)
I have no idea how I can make a foolproof address component that does not display the house number, and should always return the information regarding the list (first one) because the data always varies when dropping markers on a street when I need it to produce the same results as the list.