【问题标题】:How to add values in google map v2 marker android?如何在 google map v2 marker android 中添加值?
【发布时间】:2013-10-15 02:23:40
【问题描述】:

我在谷歌上搜索过,但我找不到。我需要这种类型的值在标记中

我不知道该怎么做,就像上面显示的那样。

GoogleMap gm;

    gm = ((SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.map))).getMap();

    gm.setOnInfoWindowClickListener(this);
    gm.addMarker(new MarkerOptions()
                            .title(jsonObj.getString("project_name"));

   @Override
   public void onInfoWindowClick(final Marker marker) {

   String name = marker.getTitle(); // this displays when marker window gets tap

}

但上面的代码只是在我点击标记窗口时显示。我只想像上面的 iamge 链接那样显示。如何做到这一点。请帮助解决问题。

提前致谢。

【问题讨论】:

    标签: android google-maps google-maps-markers google-maps-android-api-2 android-maps-v2


    【解决方案1】:

    使用安卓地图工具库

    这是该网站的链接并浏览发布的视频。

    http://googlemaps.github.io/android-maps-utils/

    1.从

    下载库

    github.com/googlemaps/android-maps-utils

    2.使用请查看此链接

    Using android-maps-utils with ADT

      IconGenerator tc = new IconGenerator(this);
      Bitmap bmp = tc.makeIcon("hello"); // pass the text you want.
    

    然后将位图设置为地图对象

      .icon(BitmapDescriptorFactory.fromBitmap(bmp))); 
    

    捕捉

    【讨论】:

      【解决方案2】:

      对于标记图标的完整免费绘图,代码可能如下所示。 在这种情况下,只有文本是标记的内容。但是你可以在画布上画任何东西。只需确保调整大小即可。

      public BitmapDescriptor getTextMarker(String text) {
      
          Paint paint = new Paint();
          /* Set text size, color etc. as needed */
          paint.setTextSize(24);
      
          int width = (int)paint.measureText(text);
          int height = (int)paint.getTextSize();
      
          paint.setTextAlign(Align.CENTER);
          // Create a transparent bitmap as big as you need
          Bitmap image = Bitmap.createBitmap(width, height, Config.ARGB_8888);
          Canvas canvas = new Canvas(image);
          // During development the following helps to see the full
          // drawing area:
          canvas.drawColor(0x50A0A0A0);
          // Start drawing into the canvas
          canvas.translate(width / 2f, height);
          canvas.drawText(text, 0, 0, paint);
          BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(image);
          return icon;
      }
      

      然后在构建标记选项时使用此方法:

      mMap.addMarker(new MarkerOptions()
      .position(new LatLng(lati, longi))
      .icon(getTextMarker("some text"));
      

      【讨论】:

      • 嗨,这里的绘画对象是什么。
      • 这是一个Paint的实例,你之前已经准备好了(作为一个成员变量)颜色,文本大小等,你希望在标记中使用。为避免大量对象分配,您通常只在 Android 中准备一次此类对象。
      • 谢谢,我已经解决了,但地图上没有显示标记。你能指导我吗?我想创建单独的标记图标,标记计数为具有不同背景颜色的文本。
      【解决方案3】:

      根据Google Maps for Android V2的文件:

      信息窗口允许您在用户访问时向他们显示信息 点击地图上的标记。默认情况下,当 如果标记具有标题集,则用户点击标记。只有一个信息 窗口一次显示。如果用户点击另一个标记, 当前窗口将被隐藏,新的信息窗口将是 显示。您可以通过调用以编程方式显示信息窗口 showInfoWindow() 在目标标记上。信息窗口可以通过以下方式隐藏 调用 hideInfoWindow()

      您可以像这样显示信息窗口:

      Marker marker = myMap.addMarker(new MarkerOptions()
                           .position(latLng)
                           .title("Title")
                           .snippet("Snippet")
                           .icon(BitmapDescriptorFactory
                           .fromResource(R.drawable.marker)));
      
      marker.showInfoWindow();
      

      我希望它对你有用。

      【讨论】:

      • 当用户点击信息窗口时会显示信息窗口,但操作人员希望显示的图像没有相同。
      • 感谢@Raghunandan,您为我节省了很多时间。再次感谢。还有一个小疑问是是否可以更改该标记图标的颜色?它显示为白色。
      • @Tinkerbell 是的,你可以有蓝色橙色绿色和红色。
      • @Tinkerbell Bitmap bmp = drawTextToBitmap(this,R.drawable.bubble_green,"mytext")。现在将位图设置为地图对象。icon(BitmapDescriptorFactory.fromBitmap(bmp)))
      猜你喜欢
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 2013-04-06
      • 1970-01-01
      • 2023-01-22
      相关资源
      最近更新 更多