2016-07-15 4 views
2

Ich verwende die Google Places-API, um Details zu einem Ort abzurufen, aber die photo_reference-Attribute für die Fotos werden nicht zurückgegeben. Warum??Die Google Places-API-Bibliothek gibt das Attribut "photo_reference" nicht zurück.

Hier ist, wie ich es bin Aufruf:

var request = { 
    placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4' 
    }; 

    service = new google.maps.places.PlacesService(document.createElement('div')); 
    service.getDetails(request, callback); 

    function callback(placeD, status) { 
    console.log(placeD); 
    console.log(JSON.stringify(placeD)); 
    if (status == google.maps.places.PlacesServiceStatus.OK) { 
     console.log(placeD); 
    } 
    } 

Und hier ist die Antwort

{ 
    "address_components":[ 
     { 
     "long_name":"5", 
     "short_name":"5", 
     "types":[ 
      "floor" 
     ] 
     }, 
     { 
     "long_name":"48", 
     "short_name":"48", 
     "types":[ 
      "street_number" 
     ] 
     }, 
     { 
     "long_name":"Pirrama Road", 
     "short_name":"Pirrama Rd", 
     "types":[ 
      "route" 
     ] 
     }, 
     { 
     "long_name":"Pyrmont", 
     "short_name":"Pyrmont", 
     "types":[ 
      "locality", 
      "political" 
     ] 
     }, 
     { 
     "long_name":"Council of the City of Sydney", 
     "short_name":"Sydney", 
     "types":[ 
      "administrative_area_level_2", 
      "political" 
     ] 
     }, 
     { 
     "long_name":"New South Wales", 
     "short_name":"NSW", 
     "types":[ 
      "administrative_area_level_1", 
      "political" 
     ] 
     }, 
     { 
     "long_name":"Australia", 
     "short_name":"AU", 
     "types":[ 
      "country", 
      "political" 
     ] 
     }, 
     { 
     "long_name":"2009", 
     "short_name":"2009", 
     "types":[ 
      "postal_code" 
     ] 
     } 
    ], 
    "adr_address":"5, <span class=\"street-address\">48 Pirrama Rd</span>, <span class=\"locality\">Pyrmont</span> <span class=\"region\">NSW</span> <span class=\"postal-code\">2009</span>, <span class=\"country-name\">Australia</span>", 
    "formatted_address":"5, 48 Pirrama Rd, Pyrmont NSW 2009, Australia", 
    "formatted_phone_number":"(02) 9374 4000", 
    "geometry":{ 
     "location":{ 
     "lat":-33.8666113, 
     "lng":151.19583239999997 
     }, 
     "viewport":{ 
     "south":-33.8669293, 
     "west":151.19521829999996, 
     "north":-33.86650529999999, 
     "east":151.1960371 
     } 
    }, 
    "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png", 
    "id":"4f89212bf76dde31f092cfc14d7506555d85b5c7", 
    "international_phone_number":"+61 2 9374 4000", 
    "name":"Google", 
    "opening_hours":{ 
     "open_now":false, 
     "periods":[ 
     { 
      "close":{ 
       "day":1, 
       "time":"1800", 
       "hours":18, 
       "minutes":0, 
       "nextDate":1468828800000 
      }, 
      "open":{ 
       "day":1, 
       "time":"0800", 
       "hours":8, 
       "minutes":0, 
       "nextDate":1468792800000 
      } 
     }, 
     { 
      "close":{ 
       "day":2, 
       "time":"1800", 
       "hours":18, 
       "minutes":0, 
       "nextDate":1468915200000 
      }, 
      "open":{ 
       "day":2, 
       "time":"0800", 
       "hours":8, 
       "minutes":0, 
       "nextDate":1468879200000 
      } 
     }, 
     { 
      "close":{ 
       "day":3, 
       "time":"1800", 
       "hours":18, 
       "minutes":0, 
       "nextDate":1469001600000 
      }, 
      "open":{ 
       "day":3, 
       "time":"0800", 
       "hours":8, 
       "minutes":0, 
       "nextDate":1468965600000 
      } 
     }, 
     { 
      "close":{ 
       "day":4, 
       "time":"1800", 
       "hours":18, 
       "minutes":0, 
       "nextDate":1469088000000 
      }, 
      "open":{ 
       "day":4, 
       "time":"0800", 
       "hours":8, 
       "minutes":0, 
       "nextDate":1469052000000 
      } 
     }, 
     { 
      "close":{ 
       "day":5, 
       "time":"1800", 
       "hours":18, 
       "minutes":0, 
       "nextDate":1469174400000 
      }, 
      "open":{ 
       "day":5, 
       "time":"0800", 
       "hours":8, 
       "minutes":0, 
       "nextDate":1469138400000 
      } 
     } 
     ], 
     "weekday_text":[ 
     "Monday: 8:00 AM – 6:00 PM", 
     "Tuesday: 8:00 AM – 6:00 PM", 
     "Wednesday: 8:00 AM – 6:00 PM", 
     "Thursday: 8:00 AM – 6:00 PM", 
     "Friday: 8:00 AM – 6:00 PM", 
     "Saturday: Closed", 
     "Sunday: Closed" 
     ] 
    }, 
    "photos":[ 
     { 
     "height":1365, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/105932078588305868215/photos\">Maksym Kozlenko</a>" 
     ], 
     "width":2048 
     }, 
     { 
     "height":3120, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/116783625253584801301/photos\">Samson Jabin</a>" 
     ], 
     "width":4160 
     }, 
     { 
     "height":1184, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/106645265231048995466/photos\">Malik Ahamed</a>" 
     ], 
     "width":1776 
     }, 
     { 
     "height":960, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/100919424873665842845/photos\">Donnie Piercey</a>" 
     ], 
     "width":1280 
     }, 
     { 
     "height":3024, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/117393076859685917096/photos\">Joann Chu</a>" 
     ], 
     "width":4032 
     }, 
     { 
     "height":5582, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/110754641211532656340/photos\">Robert Koch</a>" 
     ], 
     "width":2866 
     }, 
     { 
     "height":2988, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/103594026264127040754/photos\">Daniel Tyson</a>" 
     ], 
     "width":5312 
     }, 
     { 
     "height":2448, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/116976377324210679577/photos\">WH CHEN</a>" 
     ], 
     "width":3264 
     }, 
     { 
     "height":1184, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/106645265231048995466/photos\">Malik Ahamed</a>" 
     ], 
     "width":1776 
     }, 
     { 
     "height":4160, 
     "html_attributions":[ 
      "<a href=\"https://maps.google.com/maps/contrib/116783625253584801301/photos\">Samson Jabin</a>" 
     ], 
     "width":3120 
     } 
    ], 
    "place_id":"ChIJN1t_tDeuEmsRUsoyG83frY4", 
    "rating":4.6, 
    "reference":"CmRaAAAAXa9Pjme9u0GwglGBnp5nlj_r92tKtn3rY9mx22RTSHhZSNnYd3RvNVzl33PB_7qyhodZq_KkKx2KH9JIB0NYXuUNgVz2UKO_OMakrvJGVNrJ2Y6ue78-OVBtO6y5NdE0EhBCQrgjqWR2H2rv2ZWZrmPcGhT_f4ZFK2OYBor8uimEqGIwtBTfew", 
    "reviews":[ 
     { 
     "aspects":[ 
      { 
       "rating":3, 
       "type":"overall" 
      } 
     ], 
     "author_name":"Nila Sweeney", 
     "author_url":"https://plus.google.com/115167791509064907883", 
     "language":"en", 
     "profile_photo_url":"//lh4.googleusercontent.com/-P-5LDZmJbig/AAAAAAAAAAI/AAAAAAAAvAY/Df_n6XR0I2I/photo.jpg", 
     "rating":5, 
     "text":"Amazing place! So incredibly vibrant and hip. I love the way the office have been laid out. The way work-life balance is encouraged is truly impressive! Google, please hire me! ", 
     "time":1464213084 
     }, 
     { 
     "aspects":[ 
      { 
       "rating":0, 
       "type":"overall" 
      } 
     ], 
     "author_name":"TheHealthRetreat", 
     "author_url":"https://plus.google.com/110246682709687277403", 
     "language":"en", 
     "rating":1, 
     "text":"I spend 250 thousand dollars a year with Google adwords..\nI own a Mental Health Drug and alcohol retreat.\n\nA fictitious person Antony William posted a negative review on my Business.\n\nThis person has never attended. I asked Google for the last 8 weeks to remove the third party review, I also sent 20 times a statutory declaration to googlemybusiness then goodle reviews and google legal stating Mr Antony had never attended the program.\n\nGoogle have refused to remove the review even though it clearly breaches Googles own guidelines and the post is defamatory.\nGoogle is enabling this person to continue to hurt our business by 100000 per month since the post went up.\n\nMy request for the post to be removed is being stone walled by google.\n\nI cannot believe that Google would treat their business partners so shabbily when they are being wronged by an anonymous person or I believe competition business.\nGoogle says over and over negotiate with Antony William, how can I negotiate with someone who doesn't exist? It is frustrating and plain wrong.\n\nIf Google does this to a client who spends 250000 ausd a year with them, god help us all.\n\nBy the way if you have depression and anxiety dealing with Google, come to us and we will help you. regards Francis", 
     "time":1468373176 
     }, 
     { 
     "aspects":[ 
      { 
       "rating":0, 
       "type":"overall" 
      } 
     ], 
     "author_name":"Steve Morgan", 
     "author_url":"https://plus.google.com/103384372688674733198", 
     "language":"en", 
     "profile_photo_url":"//lh5.googleusercontent.com/-xCUbmlcbDas/AAAAAAAAAAI/AAAAAAAAIAE/OLWRkcph3xs/photo.jpg", 
     "rating":1, 
     "text":"Latest Andriod update 5.0 has broken Google Play for the Samsung Note 3. No Gmail Apo no fitbit exercise logging. Absolutely disgusting. Almost sebds ne to Apple", 
     "time":1468325696 
     }, 
     { 
     "aspects":[ 
      { 
       "rating":3, 
       "type":"overall" 
      } 
     ], 
     "author_name":"Keith Hong", 
     "author_url":"https://plus.google.com/106314339785578978358", 
     "language":"en", 
     "profile_photo_url":"//lh3.googleusercontent.com/-Z69cMMxhr-c/AAAAAAAAAAI/AAAAAAAAAEs/CbphM5oqKas/photo.jpg", 
     "rating":5, 
     "text":"Not often you get invited to the google Australia HQ. Neat spot. Love their Pirrama place but their ODI location is pretty cool too (and soon overtakin most of Fairfax) ", 
     "time":1464676368 
     }, 
     { 
     "aspects":[ 
      { 
       "rating":3, 
       "type":"overall" 
      } 
     ], 
     "author_name":"Alejandro Silva Avila", 
     "author_url":"https://plus.google.com/102339092633102421576", 
     "language":"en", 
     "profile_photo_url":"//lh5.googleusercontent.com/-WRvjv4eUHjY/AAAAAAAAAAI/AAAAAAAAUsk/6UjJkZU6U9w/photo.jpg", 
     "rating":5, 
     "text":"Completely stunning and different from anything you'd imagine. So many cool things to see and do you'd think people get lost trying to do some work haha! :)", 
     "time":1467896264 
     } 
    ], 
    "scope":"GOOGLE", 
    "types":[ 
     "point_of_interest", 
     "establishment" 
    ], 
    "url":"https://maps.google.com/?cid=10281119596374313554", 
    "utc_offset":600, 
    "vicinity":"5 48 Pirrama Road, Pyrmont", 
    "website":"https://www.google.com.au/about/careers/locations/sydney/", 
    "html_attributions":[ 

    ] 
} 

Ich kann die photo_reference bekommen Attribute, wenn ich diese URL verwenden, die Details der gleichen Stelle, um zu sehen:

https://maps.googleapis.com/maps/api/place/details/json?reference=CmRaAAAAXa9Pjme9u0GwglGBnp5nlj_r92tKtn3rY9mx22RTSHhZSNnYd3RvNVzl33PB_7qyhodZq_KkKx2KH9JIB0NYXuUNgVz2UKO_OMakrvJGVNrJ2Y6ue78-OVBtO6y5NdE0EhBCQrgjqWR2H2rv2ZWZrmPcGhT_f4ZFK2OYBor8uimEqGIwtBTfew&sensor=false&key=AIzaSyAmUTQw6a8sQESv77boQhf3tvTsaAJy09c 
+1

Komisch meinen Namen im Codebeispiel sehen :-) –

+0

Haben Sie jemals eine Lösung dafür gefunden? – Asher

+0

Haben Sie eine Lösung gefunden? – user1269586

Antwort

-4

Sie benötigen das Foto Referenz aus der Place Search oderzu erhaltenAnfrage.

Die Place Photo service, Teil des Google Places-API-Webdiensts, ist eine schreibgeschützte API, mit der Sie Ihrer Anwendung qualitativ hochwertige fotografische Inhalte hinzufügen können.

Wenn Sie Ortsinformationen mithilfe einer Ortsdetails-Anforderung erhalten, werden für relevante fotografische Inhalte Fotodeferenzen zurückgegeben.

Alle Anfragen an den Place Photo Service müssen eine photoreference enthalten. Es ist ein Zeichenfolgenbezeichner, der ein Foto eindeutig identifiziert. Foto-Referenzen werden entweder von einer Place Search- oder Place-Details-Anfrage zurückgegeben.

Ein Beispiel für ein photos[] Array ist unten dargestellt.

... 

"photos" : [ 
{ 
"html_attributions" : [], 
"height" : 853, 
"width" : 1280, 
"photo_reference" : "CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0" 
} 
... 

A Place Foto Anfrage ist eine HTTP-URL in der folgenden Form:

https://maps.googleapis.com/maps/api/place/photo?parameters

+0

Meine Frage bezieht sich speziell auf das Abrufen der photo_reference, nicht was ich tun soll, sobald ich es habe. Ich verwende eine Bitte um Ortsangabe, richtig? - service.getDetails – 99miles

+0

Dies beantwortet die Frage leider nicht – therealprashant

1

Wenn die javscript Bibliothek haben die Foto-Objekte eine Methode "getUrl" anstelle eines photo_reference. Es ist ein wenig verwirrend, aber Sie können diese Bilder durchlaufen und diese Methode mit maxHeight und/oder maxWidth aufrufen (mindestens eine von ihnen muss vorhanden sein) und es wird eine Foto-URL zurückgeben.

https://developers.google.com/maps/documentation/javascript/3.exp/reference#PlacePhoto

function callback(placeD, status) { 
    console.log(placeD); 
    console.log(JSON.stringify(placeD)); 
    if (status == google.maps.places.PlacesServiceStatus.OK) { 
     placeD.photos.forEach(photo => { 
      console.log(photo.getUrl({maxHeight: 300})) // will log a url but no photo_reference 
     }) 
    }  
} 

Leider habe ich noch nicht herausgefunden, wie eine photo_reference aus der JavaScript-Bibliothek zu erhalten.