2017-04-21 45 views
-2

这是一个json格式,我正在构建一个应用程序,在这个应用程序中我必须显示图像,但是以这种格式,它只给我图像参考,我如何显示图像引用的图像。我是Android新手,请详细回答我。我如何显示图像的参考?

{ 
    "html_attributions": [], 
    "results": [{ 
    "geometry": {}, 
    "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png", 
    "id": "b55aeae1579aa5d2313acbda97bbde5d403bfcbe", 
    "name": "Emoji Centre Pakistan", 
    "photos": [{}], 
    "place_id": "ChIJ06t7z3_A3zgRSjlPdn0hrTA", 
    "rating": 5, 
    "reference": "CmRRAAAAAhNMBwgr1K1YA3B-44ztZPHcaSLMyWH3vhd92jgZmN4WPiIKl7MMVxwa_UlP5-DJKISSKEleVZ9qFMRb0DpLA0w2h2dgn9xkYTMDpG3nxL9VI3MjaMtTa07FFHaE0xXwEhDcNE5uFDpjVvT3Y_g0Fm7TGhTyIcmuumTybtEmTBNMNdySqdwWXA", 
    "scope": "GOOGLE", 
    "types": [], 
    "vicinity": "Ataturk Avenue, Islamabad" 
    }], 
    "status": "OK" 
} 
+0

这个参考是什么?你打电话给Google API吗?如果是,那么哪个?我建议检查这个参考值的API文档。 对我来说这个参考价值似乎是BASE64编码图像 – Deb

+0

是的,我打电话给谷歌api .... nearbyplace api –

+0

看到我的答案解析图像的URL和使用Glide库 – FAT

回答

0

为了显示图像,你可以用毕加索

GRADLE 
compile 'com.squareup.picasso:picasso:2.5.2' 

Java代码

Picasso.with(context) 
    .load(url) 
    .resize(50, 50) 
    .centerCrop() 
    .into(imageView) 
0

我建议,利用这个LIB http://square.github.io/picasso/。 添加在您的app.gradle结束依赖关系

compile 'com.squareup.picasso:picasso:2.5.2' 

在代码后,添加此操作

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); 

也不要忘了添加Internet权限在AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
+0

在imageview上显示它我认为这是用于显示单个图像。关于许多图像 –

0
Glide.with(mContext).load("Your_Url") 
        .thumbnail(0.5f) 
        .crossFade() 
        .diskCacheStrategy(DiskCacheStrategy.ALL) 
        .into(Your_ImageView); 

不要忘了添加build.gradle:

compile 'com.github.bumptech.glide:glide:3.7.0' 
0

如何显示图像的reference

Google Place APIdocumentation

#参考: - 包含一个token可用于查询详细资料服务。此token可能与请求中使用的参考不同于详细信息服务。建议定期更新地点的存储参考。

虽然这个token唯一标识的地方,反过来是不正确的。 A place可能有许多有效的reference tokens

注:reference现在deprecated赞成place_id。请参阅deprecation notice

#如果你想获得icon,请尝试以下步骤:

JSON响应字符串解析图标URL

// Icon url 
String iconUrl; 

try { 

    JSONArray results = response.getJSONArray("results"); 

    JSONObject obj = results.getJSONObject(0); // 0 used for first icon image 
    iconUrl = obj.getString("icon"); // "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png"   

} catch (JSONException e) { 
    Log.e("JSON", "unexpected JSON exception", e); 
} 

2.URLImageView显示icon,使用Glide库。

使用滑翔的:

// For example 
String iconUrl = "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png"; 

ImageView imageView = (ImageView) findViewById(R.id.your_image_view); 

Glide.with(this).load(imageUrl).into(imageView); 

要使用Glide,你增加您的app/build.gradle以下dependencies

应用/的build.gradle

dependencies { 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.android.support:support-v4:19.1.0' 
} 

请参阅Glide documentation

UPDATE:

如果你想获得地方photos那么你应该使用数组photos[]

照片[]: - photoarray的对象,每个对象包含referenceimage。地点详细信息请求可能会返回最多ten照片。有关地点照片以及如何在您的应用程序中使用images的更多信息,请参阅Place Photos documentation

photo对象被描述为:

photo_reference — a string used to identify the photo when you perform a Photo request. 
height — the maximum height of the image. 
width — the maximum width of the image. 
html_attributions[] — contains any required attributions. This field will always be present, but may be empty. 

希望这将有助于〜

+0

actuallu我的图像不是在PNG我认为它是字符串形式 –

+0

形式你的JSON格式,有一个图像的URL“图标”:“https://maps.gstatic.com /mapfiles/place_api/icons/restaurant-71.png”。你已经使用json解析技术得到这个URL。查看我更新的答案获取图片网址。 – FAT

+0

井图标只是一个图标。这不是一个图像。 –

0

该响应具有JSON阵列photos。这个数组应该包含为该地点上传的照片列表。但在您的情况下,它是空的,所以这意味着该地没有可用的谷歌照片。

你可以找到更多的细节here。它定义了什么是参考,以及如何使用它来获取更多的细节。