简体   繁体   English

如何使用Google Places Photo API返回的照片?

[英]How to use the photo returned by Google Places Photo API?

I'm calling the Google Places Photo API like so in my Laravel PHP app: 我在Laravel PHP应用中像这样调用Google Places Photo API

public static function getpic ($photoreference){

    $app_id = 'XXXYYYZZZ';
    $URLToCall = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=225&photoreference=$photoreference&sensor=false&key=$app_id";

    $result = file_get_contents($URLToCall);

    return $result;
}

When I print_r $result , I get: 当我print_r $result ,我得到:

string(12902) "ÿØÿàJFIFÿá`ExifII*1&i‡.Picasa0220 á –ÿÛ„

I can't figure out how to use what's returned. 我不知道如何使用返回的内容。 I attempted to pass the string to a view, but that failed. 我试图将字符串传递给视图,但是失败了。

Any suggestion? 有什么建议吗?

According to the docs , the response is an image. 根据文档 ,响应是一个图像。 That would explain why printing it would result in binary data, like you're seeing. 这将解释为什么打印它会导致二进制数据(如您所见)。

Basically, you'll want to save this data, and then embed the image like you would in regular HTML, or just set the img src to point to the $URLToCall 基本上,您将需要保存此数据,然后像在常规HTML中一样嵌入图像,或者只是将img src设置为指向$ URLToCall

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM