我该如何显示图像参考?

时间:2017-04-21 10:35:27

标签: android json

这是一个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"
}

5 个答案:

答案 0 :(得分:0)

为了显示图像,您可以使用Picasso

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

Java代码

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

答案 1 :(得分: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);

另请不要忘记在AndroidManifest.xml中添加互联网权限

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

答案 2 :(得分: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'

答案 3 :(得分:0)

如何显示reference图片?

来自Google Place API documentation

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

虽然这个token唯一地标识了这个地方,但反之则不然。 place可能有许多有效reference tokens

注意: reference现在deprecated支持place_id。请参阅deprecation notice

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

1。URL响应字符串中解析图标JSON

// 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. 要在icon URL上显示ImageView,请使用Glide库。

使用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);

3。要使用Glide,您已在dependencies添加了以下app/build.gradle

应用/的build.gradle

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

请参阅Glide documentation

<强>更新

如果您想获得地点photos,那么您应该使用数组photos[]

照片[]: - arrayphoto个对象,每个对象包含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.

希望这会有所帮助〜

答案 4 :(得分:0)

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

您可以找到更多详细信息here。它定义了哪些引用以及如何使用它来获取更多详细信息。