I retrieve a json from google maps api like this
$http.get("https://maps.googleapis.com/maps/api/geocode/json?address="+data.SimpleProfileForm.postcode+"&sensor=false")
.success(function(data){
console.log(data);
user.location = data.results.0.address_components.3.long_name;
})
.error(function(data){
console.log("there was an error with the postcode API");
console.log(data);
})
but I get the error unexpected number on this line:
user.location = data.results.0.address_components.3.long_name;
if i delete the numbers i get 'cannot read property "long_name" of undefined'.
How am i to access the data in the array? Thanks in advance, Chris
You can't index arrays with dot-notation.
Your line of code should probably read:
user.location = data.results[0].address_components[3].long_name;