2016-06-26 61 views
1

我一直在努力與谷歌地圖infowindow內加載圖像的過去幾天。我相信我沒有正確引用URL來解析。任何人都可以請幫助我或指導我如何將解析圖像放入infowindow?這是該代碼的片段。 (注)我可以使用資源將圖像加載到infowindow中,但不能從解析中加載。 (我相信問題是我沒有引用正確的項目)在此先感謝。無法使用picasso庫加載解析圖像。 「imgUrl無法解析爲符號」

PS:此行的代碼:imgUrl的不能被解析爲一個符號

@Override 
    public void onMapReady(final GoogleMap googleMap) { 
     googleMap.setMyLocationEnabled(true); 
     this.googleMap = googleMap; 
     googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 

      // Use default InfoWindow frame 
      @Override 
      public View getInfoWindow(Marker arg0) { 
       return null; 
      } 

      // Defines the contents of the InfoWindow 
      @Override 
      public View getInfoContents(Marker marker) { 


       //icon.setImageResource(R.mipmap.back_vision_fade); 

       ParseQuery<ParseObject> query = ParseQuery.getQuery("Places"); 

       View v = getActivity().getLayoutInflater().inflate(R.layout.maps_infowindow, null); 
       v.setLayoutParams(new LinearLayout.LayoutParams((int) (mapFragment.getView().getMeasuredWidth() * .9), LinearLayout.LayoutParams.WRAP_CONTENT)); 
       ((TextView) v.findViewById(R.id.title)).setText(marker.getTitle()); 
       ((TextView) v.findViewById(R.id.desc)).setText(marker.getSnippet()); 
       ImageView icon = (ImageView) v.findViewById(R.id.imageView5); 

       Item item = new Item(); 

       try { 
        List<ParseObject> objects = query.find(); 
        for(ParseObject obj : objects){ 
         ParseGeoPoint point = obj.getParseGeoPoint("location"); 
         if(obj.getParseFile("icon")!=null) { 
          item.setIcon(obj.getParseFile("icon").getUrl()); 
          //item.downloadIcon(context); 
          item.setIcon(obj.getParseFile("icon").getUrl()); 
          Picasso.with(getActivity()).load(imgUrl).into(icon, new MarkerCallback(marker)); 

         } 
        } 
       } catch (ParseException e) { 
       } 

       return v; 

      } 
    } 

    ); 
+0

如果定義imgUrl的? –

+0

這是一個問題。我從我找到的一個例子中拿出了這個。更新:我只是嘗試了一些東西,它似乎通過將imgUrl更改爲我的Item類中定義的item.getIcon來解析圖標。但它是一個默認圖標,它不會獲取相應的圖標。更改爲: – user3078406

+0

Picasso.with(getActivity()).load(item.getIcon())。into(icon,new MarkerCallback(marker)); – user3078406

回答

1

試試這個:

Picasso.with(getActivity()).load(obj.getParseFile("icon").getUrl()).into(icon, new MarkerCallback(marker)); 
+0

是的這種作品,但我仍然顯示默認圖像,而不是正確的圖像。我有一個與不同事件關聯的解析內部圖像數組。我想顯示通訊錄圖像。現在它只顯示一個圖像。 I – user3078406

+0

你能分享這個截圖嗎? –

+0

另外它可能是一個好主意,以記錄所有obj.getParseFile(「icon」)。getUrl()爲了驗證URL正確解析。 –