0

I'm working with google maps autocomplete javascript.

This is a sample object/array? called 'place'

"result" : {
  "name" : "Hunters Landing",
  "photos" : [
     {
        "height" : 715,
        "raw_reference" : {
           "fife_url" : "photo.jpg"
        },
        "width" : 1280
     },

  "scope" : "GOOGLE",
  "types" : [ "restaurant", "food", "establishment" ],

to get the value for name I use

place.name;  // Hunters Landing

But I can't figure out how to get the image url. I've tried various combinations of [0] and so on.

place.photos[0].raw_reference[0].fife_url;

please help.

Thanks

vitalyp
  • 671
  • 4
  • 12
  • 23
  • 3
    Wouldn't it be `place.result.photos[0].raw_reference.fife_url` – Robbert Apr 10 '15 at 04:31
  • its def fife_url. that was a direct paste from a google autocomplete result. I only changed the img url... Robbert - there are like 10 images.. i just got the first one as example. – vitalyp Apr 10 '15 at 04:31
  • You're also missing the closing becket for the photos array. – Robbert Apr 10 '15 at 04:32
  • did you tryed like this : place.photos[0].raw_reference.fife_url, http://jsfiddle.net/yh031ug6/1/ – kag Apr 10 '15 at 04:38
  • place.photos[0].raw_reference.fife_url doesn't work either – vitalyp Apr 10 '15 at 04:40
  • kag. your jdfiddle works. and alert(place.name); works. I just don't get why it doesn't work for me. – vitalyp Apr 10 '15 at 04:56
  • This is my actual line of code. Name, types, scope all work. document.getElementById('image_a').value= place.photos[0].raw_reference.fife_url; – vitalyp Apr 10 '15 at 04:56
  • okay.. SO i figured out the problem. Google returns a function getURL() instead of the actual image url. They do this so you can specify the size of the image. So to get the url value this is how it has to be done. I figured this out using colsole.log. Next comment has the code – vitalyp Apr 10 '15 at 18:48
  • console.log(place.photos[i].getUrl({'maxWidth': 35, 'maxHeight': 35})); – vitalyp Apr 10 '15 at 18:50
  • this is the object that google returns after the initial object... And thats how i got to the geurl function. Object {height: 848, html_attributions: Array[0], width: 1280, getUrl: function} – vitalyp Apr 10 '15 at 18:57

1 Answers1

2

try this

place.result.photos[0].raw_reference.fife_url
theAnubhav
  • 535
  • 6
  • 16