2017-07-06 76 views
0

我已經實現了一個簡單的Google地圖,其中顯示了一個標記列表,具體取決於我擁有的列表。將圖像加載到地圖上的標記

要顯示他們,我遍歷列表和創建的每個標記,像這樣:

for (final PhotosForPlants p : photos) { 
      if (p.getLat() != null && p.getLon() != null && p.getLat() != 0.0 && p.getLon() != 0.0) // check for 0.0 
      { 
       if (p.getId() == currentPlantId) { 
        plantLocation = new LatLng(p.getLat(), p.getLon()); 
        yellowPos = plantLocation; 
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(plantLocation, 35f)); 
        Marker m = mMap.addMarker(new MarkerOptions().position(plantLocation) 
          .icon(BitmapDescriptorFactory 
            .defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))); 

        m.setTag(p); 
        markers.add(m); 
       } else { 
        plantLocation = new LatLng(p.getLat(), p.getLon()); 
        positions.add(plantLocation); 
        positionSave = index; 
        Marker m = mMap.addMarker(new MarkerOptions().position(plantLocation) 
          .icon(BitmapDescriptorFactory 
            .defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); 

        m.setTag(p); 
        markers.add(m); 
       } 

      } 
      index++; 
     } 
    } 

的而不是一個簡單的標記的圖像,我需要有一些像從我的服務器加載一個正方形的圖像,我嘗試用畢加索的,但如果我得到任何的問題做這種方式得到位,我不知道:

public void loadBitmap(String url) { 

     if (loadtarget == null) loadtarget = new Target() { 
      @Override 
      public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 
       // do something with the Bitmap 
       handleLoadedBitmap(bitmap); 
      } 

      @Override 
      public void onBitmapFailed(Drawable errorDrawable) { 

      } 

      @Override 
      public void onPrepareLoad(Drawable placeHolderDrawable) { 

      } 

     }; 

     Picasso.with(this).load(url).into(loadtarget); 
    } 

    public Bitmap handleLoadedBitmap(Bitmap b) { 
     return b; 
    } 

我的主要問題是,我不知道我可以retrive每個圖像加載爲特定的標記,以及如何使用我的地圖設置IP:S。

任何幫助?

回答

0

回答你問題的第二部分:如果你有一個位圖對象,你可以以使用設備無關的標記與

Marker m = mMap.addMarker(new MarkerOptions().position(plantLocation) 
         .icon(BitmapDescriptorFactory.fromBitmap(myBitmap))); 

修改代碼。

0

試試這個

Marker source = mMap.addMarker(
       new MarkerOptions() 
    .position( 
     new LatLng(
      Double.parseDouble(info.getLatitude()), 
      Double.parseDouble(info.getLongitude()))) 
    .title(info.getBankName()) 
    .snippet(info.getBankAddress())  
    .icon(BitmapDescriptorFactory.fromResource(getBitmap(url)))); 



public static Bitmap getBitmap(String src) { 
    try { 
     URL url = new URL(src); 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
     connection.setDoInput(true); 
     connection.connect(); 
     InputStream input = connection.getInputStream(); 
     Bitmap myBitmap = BitmapFactory.decodeStream(input); 
     return myBitmap; 
    } catch (IOException e) { 
     // Log exception 
     return null; 
    } 
}