【问题标题】:Adding an image from web service to map Marker icon将图像从 Web 服务添加到地图标记图标
【发布时间】:2016-01-28 01:53:43
【问题描述】:

我在可绘制文件夹中有一个图标图像,我将其设置为映射标记图标,但我需要将图像设置为现有标记 click to See the white portion of the image(1st) 上方我想显示图像 (2nd) this image to be shown on that previous white portion of that 1st image 的位置。

*第一个图像是一个自定义标记,它是静态的,我从可绘制文件夹中获取它。

*第二个是我从网络服务 url 获取的简单图像。**

LatLng userPosition = new LatLng(
                    Double.parseDouble(item.latitude),
                    Double.parseDouble(item.longitude));
                googleMap.addMarker(new MarkerOptions()
                    .position(userPosition)
                    .title(item.vendorname)
                    .snippet("Service : " + item.category_name)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.location_pin))

以上代码用于查看地图上的标记图标。但我需要在其上方显示另一张图片。所以我通过这样的网络服务获取网址(以下代码)。

try {   
     URL url = new URL(CommonUtilities.Thumb_Call+ item.vendor_icon);
     bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
      bmp = BitmapFactory.decodeFile(String.valueOf(url));
     } 
     catch (Exception e) 
      {
         e.printStackTrace();
    }

请帮我将图像设置在来自 url 的标记上方。

【问题讨论】:

  • 嘿,点击下面的链接,它可能会给你一些想法-Customize marker icon
  • 我知道如何设置标记,但不知道如何在其上方设置另一个图像
  • 您可以使用图片编辑工具在第一张图片上添加第二张图片...这是我能看到的唯一方法。非程序化它可能,程序化我不这么认为
  • 你知道@sud有什么编辑工具吗??
  • google上有很多在线照片编辑工具。只需谷歌“在线照片编辑器”

标签: android web-services google-maps google-maps-api-3 google-maps-markers


【解决方案1】:

这个问题可以解决如下:

首先创建custom_marker_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/markertoemp"
    tools:ignore="VectorDrawableCompat" />

<ImageView
    android:id="@+id/inside"
    android:layout_width="32.25dp"
    android:layout_height="32.25dp"
    android:layout_centerInParent="true"
    android:layout_marginBottom="22dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/imageView4"
    app:layout_constraintEnd_toEndOf="@+id/imageView4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/imageView4"
    app:srcCompat="@drawable/ic_delevery_primary"
    tools:ignore="MissingConstraints,VectorDrawableCompat" />

</android.support.constraint.ConstraintLayout>

现在去java,把这个方法:

    private void setUpMap(final EmpMarker emp) {
    LatLng empLatLog = new LatLng(emp.getLatitude(), emp.getLongitude());

    View marker = ((LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.lyout.custom_marker_layout, null);
    ImageView imageView = marker.findViewById(R.id.inside);
    GlideApp.with(activity).load(URLs.Glide_URL + imgeSub).apply(RequestOptions.circleCropTransform()).into(imageView);

    new Handler().postDelayed(() -> {
        customMarker = mMap.addMarker(new MarkerOptions()
                .position(empLatLog)
                .icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(marker))));
        customMarker.setTag(emp);
    }, 10);
 }

祝你好运:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    相关资源
    最近更新 更多