2017-04-21 108 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。它定義了什麼是參考,以及如何使用它來獲取更多的細節。