简体   繁体   中英

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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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