Local Weather + Displaying the Address

I am almost ready to submit my challenge, but there is one strange thing happening with the Google Maps API. I used the code var myLocation = json.results[1].formatted_address; to get an address like this: City, Province, Country. This works most of the time, but once in a while, it give me the entire street address which I do not want. Does anybody know why this is happening? I believe there is another place in the JSON that should be for the entire street address.

According the the documentation:

formatted_address is a string containing the human-readable address of this location.

Often this address is equivalent to the postal address. Note that some countries, such as the United Kingdom, do not allow distribution of true postal addresses due to licensing restrictions.

The formatted address is logically composed of one or more address components. For example, the address “111 8th Avenue, New York, NY” consists of the following components: “111” (the street number), “8th Avenue” (the route), “New York” (the city) and “NY” (the US state).

Do not parse the formatted address programmatically. Instead you should use the individual address components, which the API response includes in addition to the formatted address field.

Okay, thanks. I’ll do it that way. From what I see for my location, there are two formatted_address: in results[0].formatted_address it shows the entire street address, but in results[1].formatted_address it shows just the city, province and country. That was the one I was trying to use.

I used the individual components and got the result I was looking for. Thank you.

Actually, that last solution is not getting consistent results either. Right now I tested it, and got the municipality, the country and part of the postal code. Why does the type of information I’m getting from Google keep changing? Does the setup of the JSON file keep changing?