将图像加载到地图上的标记

时间:2017-07-06 09:31:17

标签: java android google-maps geolocation marker

我已经实现了一个简单的谷歌地图,其中我根据我的列表显示标记列表。

要显示它们,我会遍历列表并创建每个标记,如下所示:

.single-image{
  border: 1px solid orange;
  width: 100%;
  text-align: center;
  margin: 0px 0px 15px 0px;
  float: right;
  height: 405px;
}

.img-wrap{
  padding-bottom: 50px;
  padding-top: 25px;
  height:250px;
  overflow:hidden;
}

而不是一个简单的标记图像,我需要有一个像我的服务器加载的方形图像,我尝试使用毕加索,但我不知道我是否有任何问题这样做,以获得位图:

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++;
        }
    }

我的主要问题是我不知道我如何能够检索为特定标记加载的每个图像,以及如何使用我的地图设置它:S。

任何帮助?

2 个答案:

答案 0 :(得分:0)

回答你问题的第二部分:如果你有一个Bitmap对象,你可以用

修改你的代码
 Marker m = mMap.addMarker(new MarkerOptions().position(plantLocation)
                        .icon(BitmapDescriptorFactory.fromBitmap(myBitmap)));

以使用myBitmap作为标记。

答案 1 :(得分: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;
    }
}
相关问题