了解Google Places Photos API的响应 [英] Understanding the response from the Google Places Photos API
问题描述
我正在使用 Google Place Photos API 进行调用jquery ajax,并根据之前检索的照片引用检索响应.该请求似乎正在处理中,但是我不了解响应的格式/如何将其转换为图像.
$.ajax({网址:https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0& key = myKey',方法:获取"}).then(function(imageResponse){console.log(图像响应",imageResponse);})
输出采用以下格式...
JFIF * ExifII *1Google XICC_PROFILEHapplscnrRGB XYZ acspAPPLappl -applrXYZgXYZbXYZ0wtptDchadX,rTRC gTRC bTRC desc ncprt Adscm XYZtK> XYZZs& XYZ(W 3XYZ R sf32Blcurv3mlucenUS $ esES,LdaDK4dede,fiFI(frFU
您应使用 Places Photos网络服务可以直接添加到< img>
源中,如下所示:
<代码>< IMG SRC =https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0&key=YOUR_API_KEY></img>
另请参阅以下相关问题:
在哪里做我要检索photo_reference值来发出Google Places Photos请求吗?
Google Place Photos API using jquery ajax, and retrieving a response based on a photo reference that was retrieved earlier. The request seems to be going through, but I don't understand the format of the response/how I could convert this into an image.
$.ajax({
url: 'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0&key=myKey',
method: 'GET'
})
.then(function(imageResponse) {
console.log("Image response", imageResponse);
})
The output is in the following format...
����JFIF��*ExifII*1Google��XICC_PROFILEHappl scnrRGB XYZ �acspAPPLappl���-appl rXYZgXYZbXYZ0wtptDchadX,rTRC�gTRC�bTRC�desc�ncprt�Adscm��XYZ tK>�XYZ Zs��&XYZ (W�3XYZ �R�sf32B����&�������������lcurv3mlucenUS$�esES,LdaDK4�deDE,�fiFI(�frFU<�itIT,rnlNL$noNO xptBR(JsvSE*�jaJPkoKR2zhTW2zhCN�Kameran RGB-profiiliRGB-profil f�r Kamera0�0�0� RGB 0�0�0�0�0�0�exOMv�j_ RGB �r_icϏ�Perfil RGB para C�maraRGB-kameraprofilRGB-Profil f�r Kamerasv�g: RGB cϏ�e�N�RGB-beskrivelse til KameraRGB-profiel Camera�t�T�| RGB ��\��|Perfil RGB de C�meraProfilo RGB FotocameraCamera RGB ProfileProfil RVB de l appareil-phototextCopyright 2003 Apple Computer Inc., all rights reserved.descCamera RGB ProfileCamera RGB Profile���
...and so forth for quite a while.
You should use the Place Photos client-side service from the JavaScript API's Places Library if you are coding in client-side JavaScript, to avoid CORS errors from same-origin policy.
Otherwise, the images you get from the Places Photos web service can be directly added to <img>
sources as follows:
<img src="https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CnRvAAAAwMpdHeWlXl-lH0vp7lez4znKPIWSWvgvZFISdKx45AwJVP1Qp37YOrH7sqHMJ8C-vBDC546decipPHchJhHZL94RcTUfPa1jWzo-rSHaTlbNtjh-N68RkcToUCuY9v2HNpo5mziqkir37WU8FJEqVBIQ4k938TI3e7bf8xq-uwDZcxoUbO_ZJzPxremiQurAYzCTwRhE_V0&key=YOUR_API_KEY"></img>
Also see these related questions:
Where do I retrieve the photo_reference value to make a Google Places Photos request?
How to get a an image of a place from a nearby search from google api with an angular app?
Hope this helps!
这篇关于了解Google Places Photos API的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!