2017-07-06 35 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; 
    } 
} 
相关问题