【问题标题】:Load image to markers on maps将图像加载到地图上的标记
【发布时间】:2017-07-06 09:31:16
【问题描述】:

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

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

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

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

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

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

有什么帮助吗?

【问题讨论】:

    标签: java android google-maps geolocation marker


    【解决方案1】:

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

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

    为了使用 myBitmap 作为标记。

    【讨论】:

      【解决方案2】:

      试试这个

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

      【讨论】:

        猜你喜欢
        • 2016-04-14
        • 1970-01-01
        • 2011-09-27
        • 2023-02-11
        • 2016-01-28
        • 1970-01-01
        • 2014-01-19
        • 2016-07-07
        • 1970-01-01
        相关资源
        最近更新 更多