gpt4 book ai didi

android - 获取照片引用

转载 作者:搜寻专家 更新时间:2023-11-01 09:50:20 30 4
gpt4 key购买 nike

我正在尝试找到一种从 google places api 获取照片引用字符串的方法。这是google的格式:

 "photos" : [
{
"height" : 768,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/114756359878708427597/photos\"\u003eHotel Olympic\u003c/a\u003e"
],
"photo_reference" : "CmRdAAAAGWSabKG9f1wwRa1-dg0RVlb_m54RQDO023QTxEgOdFvlE2KjnK9Saxiqnxanr0yTCdbEg183RUk0kncFVwmFoQ8kn5yjnPHGZ-3-vi8Jck-6MbfJLU__h7hibPJ4tko3EhAhSR1B_4-eT4c6A_s_32I_GhTFiO19eMhOD5x5xYfB4DN3ABOtKA",
"width" : 1024
}
]

如何获取照片引用字符串?有没有办法做到这一点,还是我必须做其他事情?

这是我的java代码:

private HashMap<String, String> getPlace(JSONObject jPlace){
HashMap<String, String> place = new HashMap<String, String>();
String photo_reference= "-NA-";
if(!jPlace.isNull("photos")){
//something to do here
}
//a string builder here to create the url
place.put("photo", theUrl);
}

其中 jPlace 是来自 google places api 的 JSONObject 格式的地方

Ofcource 还有更多代码,但我只是上传了我获得 jsonObject 的部分

最佳答案

这是我在 //do something here 部分必须做的:

        StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/photo?maxwidth=50&photoreference=");

JSONArray photos = jPlace.getJSONArray("photos");

//Run for loop for getting photo_reference string in each object

for (int i=0; i <= photos.length; i++){
JSONObject getPhtotos = photos.getJSONObject(i);
String photo_reference = getPhtotos.getString("photo_reference");
sb.append(photo_reference);
sb.append("&key=...");
}

关于android - 获取照片引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36475153/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com