【问题标题】:Loading image for Marker saved in SQlite Database为 SQlite 数据库中保存的标记加载图像
【发布时间】:2015-01-23 17:27:24
【问题描述】:

我已经使用 SQLite 数据库在我的应用程序中保存了标记 ID 和图像文件路径。我目前遇到的问题是,当再次加载地图时,标记会显示在用户添加它们的位置,但是通过相机意图(图像路径)为该标记拍摄的图像不会随标记一起加载。

所以解释一下,我的标记有一个CustomInfoWindow,它显示一个标题和sn-p(标记的位置)然后有一个ImageView,它在放置标记后最初会显示图像。但是在重新加载应用程序时,图像消失了,但显示了标题和片段。

所以在保存图像文件路径和我使用的标记 ID 时:

contentValues.put(LocationsDB.FIELD_IMAGE, markerId);
contentValues.put(LocationsDB.FIELD_FILEPATH, image.getAbsolutePath());

它保存的数据是这样的:

m15  --> Marker ID
/storage/emulated/0/My Folder/MyImage_123.jpg --> File Path

然后在应用启动后加载标记时:

String filep = null;
String id = null;

id = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_IMAGE));
filep = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_FILEPATH));

drawMarker(thePoint, title, snippet, id, filep);

那么在我的drawMarker 方法中:

private void drawMarker(LatLng point, String title, String snippet, String id, String filep) {
Marker marker = googleMap.addMarker(new MarkerOptions()
.title(title)
.snippet(snippet)
.position(thePoint)
.icon(BitmapDescriptorFactory
      .defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
markerId = marker.getId();

以及在显示初始图片时,title和sn-p:

@Override
  public View getInfoContents(Marker marker)
    {
View v  = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
  ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon);
  TextView titleText = (TextView) v.findViewById(R.id.TitleId);
  titleText.setText(marker.getTitle());
  TextView snippetText = (TextView) v.findViewById(R.id.SnippetId);
  snippetText.setText(marker.getSnippet());
  Bitmap bitmap = myMarkersHash.get(marker.getId());
  markerIcon.setImageBitmap(bitmap);
  return v;

所以我知道我需要以某种方式(在 drawMarker 方法中)实现 filepid 以便我可以显示该标记的图像。但我不确定该怎么做。我不想用图标代替图像,而是希望在 imageview 中使用带有图像的默认标记。

我已经为此苦苦挣扎了几个星期。所以现在我希望有人能够提供帮助。

【问题讨论】:

    标签: android sqlite google-maps


    【解决方案1】:

    编辑:

    抱歉误解了你的问题。

    您可以通过 HashMap 保存特定标记的文件路径,如下所示:

    private HashMap<Marker, String> mMarkerImages = new HashMap<>();
    
    private void drawMarker(LatLng point, String title, String snippet, String id, String filep) {
        Marker marker = googleMap.addMarker(new MarkerOptions()
                .title(title)
                .snippet(snippet)
                .position(thePoint)
                .icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
        mMarkerImages.put(marker, filep);
    }
    

    稍后您可以使用相同的 HashMap 来获取特定于某个标记的文件路径:

    @Override
    public View getInfoContents(Marker marker) {
        String filep = mMarkerImages.get(marker);
        if (filep != null) {
            // File path was set for this marker, display your image
        }
        return null;
    }
    

    【讨论】:

    • 谢谢,但是如果我使用它,那么默认标记将是图像,而不是标准的普通老式标记 :-) 可能没有办法仍然保留标记并显示CustomInfoWindow的imageView中的图片?
    • 谢谢,不过好像还是不行。我现在可能很累,所以没有那么集中注意力。我会在早上处理它并回复你。再次感谢您的帮助。
    猜你喜欢
    • 2014-11-24
    • 2020-02-10
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-06-29
    • 2012-12-16
    • 2020-11-30
    • 2013-10-04
    相关资源
    最近更新 更多