社区首页 >问答首页 >制作一个标记携带自定义信息以供点击时使用(安卓,Google v2)

制作一个标记携带自定义信息以供点击时使用(安卓,Google v2)
EN

Stack Overflow用户
提问于 2014-10-20 00:26:45
回答 2查看 566关注 0票数 1

我有以下代码:

代码语言:javascript
代码运行次数:0
复制
public class AlertViewOnMap extends Activity {

    //declarations
    ArrayList<String> dateCreatedAtList = new ArrayList<String>();

    TextView busNumberTextView;
    TextView descriptionTextView;
    TextView alertTimeTextView;

    DateFormat dateFormat = new SimpleDateFormat("HH:mm");


protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    this.setContentView(com.fourbox.bocterapp.R.layout.details_design);

    busNumberTextView = (TextView) findViewById(R.id.textViewAlertBusNumber);
    descriptionTextView = (TextView) findViewById(R.id.textViewAlertDescription);
    alertTimeTextView = (TextView) findViewById(R.id.textViewAlertTime);

    busNumber = getIntent().getIntExtra("busNumber", 0);
    description = getIntent().getStringExtra("description");
    coordinatesLatitude =  getIntent().getDoubleExtra("coordinatesLatitude", 0);
    coordinatesLongitude = getIntent().getDoubleExtra("coordinatesLongitude", 0);

    alertTime.setTime(getIntent().getLongExtra("createdAt", 0));

    busNumberList = getIntent().getStringArrayListExtra("busNumberList");
    descriptionList = getIntent().getStringArrayListExtra("descriptionList");
    coordinatesLatitudeList =     getIntent().getStringArrayListExtra("coordinatesLatitudeList");
coordinatesLongitudeList =     getIntent().getStringArrayListExtra("coordinatesLongitudeList");
dateCreatedAtList = getIntent().getStringArrayListExtra("dateCreatedAtList");

    GoogleMap mMap;
    mMap = ((MapFragment)     getFragmentManager().findFragmentById(com.fourbox.bocterapp.R.id.mapFragment)).getMap();
    reuniteAlertListFromGetExtra();
    placeAllMarkersOnMap(mMap, alertsList);

    LatLng latLng = new LatLng(coordinatesLatitude, coordinatesLongitude);

    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(latLng) // Center Set
            .zoom(18.0f)                // Zoom
            .bearing(0)                // Orientation of the camera to east
            .tilt(30)                   // Tilt of the camera to 30 degrees
            .build();                   // Creates a CameraPosition from the builder
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    busNumberTextView.setText(String.valueOf(busNumber));
    descriptionTextView.setText(description);
    alertTimeTextView.setText(String.valueOf(dateFormat.format(alertTime)));    
    }

    public void placeAllMarkersOnMap(GoogleMap mMap, ArrayList<Alert> alertsList) {

        for(int i =0; i<alertsList.size(); i++) {

            mMap.addMarker(new MarkerOptions()
                    .position(new     LatLng(alertsList.get(i).getCoordinates().getLatitude(),     alertsList.get(i).getCoordinates().getLongitude()))
                    .title(alertsList.get(i).getDescription())
                    .snippet(String.valueOf(alertsList.get(i).getBusNumber())
                    ));
        }
    }

    public void reuniteAlertListFromGetExtra() {

        for (int i =0; i<busNumberList.size(); i++) {

            Alert alert = new Alert();
            ParseGeoPoint parseGeoPoint = new ParseGeoPoint();

            parseGeoPoint.setLatitude(Double.valueOf(coordinatesLatitudeList.get(i)));
            parseGeoPoint.setLongitude(Double.valueOf(coordinatesLongitudeList.get(i)));

            alert.setBusNumber(Integer.valueOf(busNumberList.get(i)));
            alert.setDescription(descriptionList.get(i));
            alert.setCoordinates(parseGeoPoint);
            alert.setCreatedAt(new Date(Long.valueOf(dateCreatedAtList.get(i))));

            alertsList.add(alert);
        }
    }

    public GoogleMap.OnMarkerClickListener getInfoMarkerClickListener() {
        return new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {

                busNumberTextView.setText(marker.getSnippet());
                descriptionTextView.setText(marker.getTitle());
                alertTimeTextView.setText(dateCreatedAtList.get(marker.getId()));
                marker.showInfoWindow();
                return true;
            }
        };
    }    
}

我的问题是:我想添加要存储在标记中的自定义数据,这样当我单击它时,"alerTimeTextView“将从"dateCreatedAtList”获得标记创建时间?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-20 00:49:55

尝试这样做,希望,这将帮助您解决您的问题。

定义一个 HashMap ,以标记作为密钥,Alert作为值,当创建新的标记在地图上添加时,将此标记添加到HashMap中,并在特定<代码>E 118标记标记>E 213标记<代码>E 219信息窗口时,从< you >E 116哈希图>E 217数据中添加来自E 112警报E 213的特定<<代码>E 114警报。

代码语言:javascript
代码运行次数:0
复制
public class AlertViewOnMap extends Activity {

    //declarations
    ArrayList<String> dateCreatedAtList = new ArrayList<String>();

    TextView busNumberTextView;
    TextView descriptionTextView;
    TextView alertTimeTextView;

    DateFormat dateFormat = new SimpleDateFormat("HH:mm");
    private HashMap<Marker,Alert> markerDataMap;


    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(com.fourbox.bocterapp.R.layout.details_design);

        busNumberTextView = (TextView) findViewById(R.id.textViewAlertBusNumber);
        descriptionTextView = (TextView) findViewById(R.id.textViewAlertDescription);
        alertTimeTextView = (TextView) findViewById(R.id.textViewAlertTime);

        busNumber = getIntent().getIntExtra("busNumber", 0);
        description = getIntent().getStringExtra("description");
        coordinatesLatitude =  getIntent().getDoubleExtra("coordinatesLatitude", 0);
        coordinatesLongitude = getIntent().getDoubleExtra("coordinatesLongitude", 0);

        alertTime.setTime(getIntent().getLongExtra("createdAt", 0));

        busNumberList = getIntent().getStringArrayListExtra("busNumberList");
        descriptionList = getIntent().getStringArrayListExtra("descriptionList");
        coordinatesLatitudeList =     getIntent().getStringArrayListExtra("coordinatesLatitudeList");
        coordinatesLongitudeList =     getIntent().getStringArrayListExtra("coordinatesLongitudeList");
        dateCreatedAtList = getIntent().getStringArrayListExtra("dateCreatedAtList");

        GoogleMap mMap;
        mMap = ((MapFragment)     getFragmentManager().findFragmentById(com.fourbox.bocterapp.R.id.mapFragment)).getMap();
        reuniteAlertListFromGetExtra();
        placeAllMarkersOnMap(mMap, alertsList);

        LatLng latLng = new LatLng(coordinatesLatitude, coordinatesLongitude);

        CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(latLng) // Center Set
                .zoom(18.0f)                // Zoom
                .bearing(0)                // Orientation of the camera to east
                .tilt(30)                   // Tilt of the camera to 30 degrees
                .build();                   // Creates a CameraPosition from the builder
        mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

        busNumberTextView.setText(String.valueOf(busNumber));
        descriptionTextView.setText(description);
        alertTimeTextView.setText(String.valueOf(dateFormat.format(alertTime)));
    }

    public void placeAllMarkersOnMap(GoogleMap mMap, ArrayList<Alert> alertsList) {
        markerDataMap = new HashMap<Marker, Alert>();
        for(int i=0; i<alertsList.size(); i++) {
            markerDataMap.put(mMap.addMarker(new MarkerOptions()
                    .position(new     LatLng(alertsList.get(i).getCoordinates().getLatitude(),     alertsList.get(i).getCoordinates().getLongitude()))
                    .title(alertsList.get(i).getDescription())
                    .snippet(String.valueOf(alertsList.get(i).getBusNumber())
                    )),alertsList.get(i));

        }
    }

    public void reuniteAlertListFromGetExtra() {

        for (int i =0; i<busNumberList.size(); i++) {

            Alert alert = new Alert();
            ParseGeoPoint parseGeoPoint = new ParseGeoPoint();

            parseGeoPoint.setLatitude(Double.valueOf(coordinatesLatitudeList.get(i)));
            parseGeoPoint.setLongitude(Double.valueOf(coordinatesLongitudeList.get(i)));

            alert.setBusNumber(Integer.valueOf(busNumberList.get(i)));
            alert.setDescription(descriptionList.get(i));
            alert.setCoordinates(parseGeoPoint);
            alert.setCreatedAt(new Date(Long.valueOf(dateCreatedAtList.get(i))));

            alertsList.add(alert);
        }
    }

    public GoogleMap.OnMarkerClickListener getInfoMarkerClickListener() {
        return new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                Alert alert = markerDataMap.get(marker);
                busNumberTextView.setText(alert.getDescription());
                descriptionTextView.setText(alert.getBusNumber());
                alertTimeTextView.setText(dateCreatedAtList.get(alert.getId()));
                marker.showInfoWindow();
                return true;
            }
        };
    }
}
票数 5
EN

Stack Overflow用户

发布于 2014-10-20 00:57:11

要问你的问题:似乎马克不允许任何“集合”方法,如视图的标签,为每个这里

我认为哈雷什的解决方案一般是正确的。

我只需对以下方法做如下更正:

代码语言:javascript
代码运行次数:0
复制
public GoogleMap.OnMarkerClickListener getInfoMarkerClickListener()

这句话:

代码语言:javascript
代码运行次数:0
复制
 alertTimeTextView.setText(dateCreatedAtList.get(alert.getId()));

应:

代码语言:javascript
代码运行次数:0
复制
 alertTimeTextView.setText(alert.getCreatedAt());
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26461348

复制
相关文章
将tensor转换为图像_tensor转int
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/11/07
11.4K0
面试官:请用纯 JS 实现,将 HTML 网页转换为图像
由于安全原因,我们不能直接将HTML绘制到Canvas中。我们将采用另一种更安全的方法。
前端修罗场
2023/10/07
7050
面试官:用纯 JS 将 HTML 页面转换为图像,有什么思路
在工作时,需要实现一个功能:把一个HTML网页的转换为图像。我想到的第一个想法是使用第三方库,但像dom-to-image或使用Chrome Headless,如Puppeteer。那如何使用纯Javascript解决这种需求呢?
前端修罗场
2022/07/29
2.3K0
将png格式的图像转换为jpg
import osfrom PIL import Imagedirname_read="D:\dataset\cityscapes\cityscape_voc_clean\JPEGImages_png\\"dirname_write="D:\dataset\cityscapes\cityscape_voc_clean\JPEGImages_jpg\\"names=os.listdir(dirname_read)count=0for name in names: img=Image.open(dirna
狼啸风云
2020/07/16
2.3K0
将读取的文本内容转换为特定格式
在完成小组作业的过程中,我们开发的“游客信息管理系统”中有一个“查询”功能,就是输入游客的姓名然后输出全部信息。要实现这个功能就需要从保存到外部的目录中读取文本并且复原成原来的形式。
算法与编程之美
2023/08/22
1760
将读取的文本内容转换为特定格式
javascript html转换成markdown,如何使用Turndown使用JavaScript将HTML转换为Markdown[通俗易懂]
许多项目不是从定义的结构开始, 而是随着时间的流逝而变化。例如, 一个基本博客可能从一开始就使用HTML格式将其内容存储在数据库中, 但是由于其简单性, 总有一天某人可能希望开始使用Markdown而不是HTML, 在这种情况下, 你需要从一种格式转换为另一种格式。如果你将服务器端逻辑与JavaScript(Node.js)一起使用, 甚至直接在浏览器中将HTML转换为编辑器中的Markdown, 则可以使用Turndown库轻松地完成此类任务, HTML到用JavaScript编写的Markdown转换器。
全栈程序员站长
2022/10/04
4K0
将图像转换为JPG或GIF字节流。
其实这个东西真的没有什么可谈的,完全都是一堆API函数的调用,不过呢,隔那么一段时间就有人在那里问,而且一般也得不到正确的答案,因此,我还是画蛇添足,共享一下这些调用的苦力活吧。
用户1138785
2019/09/11
1.8K0
将图像转换为JPG或GIF字节流。
用于将图像转换为较小的块以执行图像处理任务的函数。
fig2texPS.m function fig2texPS(varargin) EPS=1e-10; s = warning('query', 'all'); % save warnings warning('off','all'); % disable all warnings % clc % clear screen %% % INITIALIZATION % create new struct 'globals' that contains all plot settings with th
裴来凡
2022/05/28
6.7K0
用于将图像转换为较小的块以执行图像处理任务的函数。
JavaScript SheetJS将 Html 表转换为 Excel 文件
在本教程中,我们可以在客户端从我们的 HTML 表数据创建一个 excel 文件。即使用javascript将HTML 表导出到Excel (.xlsx)。
全栈程序员站长
2022/09/09
5.4K0
使用Python将PDF转换为Excel
在本文中,我们将了解如何使用Python将PDF转换为Excel。如果你处理数据,那么很可能已经或将不得不处理存储在.pdf文件中的数据。从PDF复制表格并将其直接粘贴到Excel是很困难的,在大多数情况下,我们从PDF文件中复制的是文本,而不是格式化的Excel表格。因此,当将数据粘贴到Excel中时,我们会看到一块文本被压缩到一个单元格中。
fanjy
2022/03/07
3.9K0
使用Python将PDF转换为Excel
将网页 DOM 转换为图像:分享刻不容缓
这些开源项目都是在处理网页截图和将DOM节点转换为图像方面非常有用的工具。它们提供了跨平台支持、简单易用的API接口以及可自定义选项来满足各种需求。无论是需要在浏览器上直接对网页进行截屏,还是将任意DOM节点转换为矢量或光栅图像,这些项目都能够很好地完成任务。此外,它们还支持设置输出图像质量、大小等参数,并且可以嵌入Web字体并进行优化处理。总之,在保留原始布局与样式同时获得高质量图片方面,这些开源项目表现出色。
小柒
2023/08/10
7140
将网页 DOM 转换为图像:分享刻不容缓
人工智能使用深度学习将2D图像转换为3D图像
加利福尼亚大学洛杉矶分校的一个研究小组设计了一种扩展荧光显微镜功能的技术,该技术使科学家能够使用特殊照明条件下发光的染料精确标记活细胞和组织的各个部分。研究人员利用人工智能将二维图像转换成虚拟三维切片的堆栈,这些三维切片显示了生物体内的活动。
AiTechYun
2019/11/12
2.5K0
java map 转string_java-将Map <String,Object>转换为Map <String,String>
Map map = new HashMap(); //Object is containing String
全栈程序员站长
2022/08/25
12.3K0
Birdge.NET:将C#代码转换为JavaScript
Birdge.NET 是一个可以将C#代码转换为JavaScript的开源编译器,由 Object.NET于2015年5月推出。它允许开发者使用C#编写平台独立的移动、Web和桌面应用,并运行在iOS、Windows、Mac、Linux及其它任意支持JavaScript的设备上。 Birdge.NET的最新版本是 2015年8月17日发布的1.8版本 。该版本的一项特性是 支持多平台操作系统 。这一特性可以让 Birdge.NET 本身运行在多个平台上。目前,Birdge.NET可以运行在Windows、L
逸鹏
2018/04/09
3.3K0
组件分享之后端组件——docconv组件将文档转换为纯文本
近期正在探索前端、后端、系统端各类常用组件与工具,对其一些常见的组件进行再次整理一下,形成标准化组件专题,后续该专题将包含各类语言中的一些常用组件。欢迎大家进行持续关注。
cn華少
2022/03/06
7270
组件分享之后端组件——cat组件将文档转换为纯文本
近期正在探索前端、后端、系统端各类常用组件与工具,对其一些常见的组件进行再次整理一下,形成标准化组件专题,后续该专题将包含各类语言中的一些常用组件。欢迎大家进行持续关注。
cn華少
2022/03/06
5370
面试官:请使用 OpenGL ES 将 RGB 图像转换为 YUV 格式。我 ……
最近,有位读者大人在后台反馈:在参加一场面试的时候,面试官要求他用 shader 实现图像格式 RGB 转 YUV ,他听了之后一脸懵,然后悻悻地对面试官说,他只用 shader 做过 YUV 转 RGB,不知道 RGB 转 YUV 是个什么思路。
字节流动
2021/06/09
5.2K1
面试官:请使用 OpenGL ES 将 RGB 图像转换为 YUV 格式。我 ……
如何使用Python将图像转换为NumPy数组并将其保存到CSV文件?
Python 是一种功能强大的编程语言,具有大量的库和模块。其中一个库是 NumPy,它用于数值计算和处理大型多维数组和矩阵。另一个用于Python图像处理的流行库是Pillow,它是Python Imaging Library(PIL)的一个分支。
很酷的站长
2023/08/11
4790
如何使用Python将图像转换为NumPy数组并将其保存到CSV文件?
使用格拉姆角场(GAF)以将时间序列数据转换为图像
这篇文章将会详细介绍格拉姆角场 (Gramian Angular Field),并通过代码示例展示“如何将时间序列数据转换为图像”。
deephub
2022/04/14
3.4K0
使用格拉姆角场(GAF)以将时间序列数据转换为图像
使用WebP Server在不改变URL的情况下将网站图像转换为WebP
WebP Server这是一个基于 Golang 的服务器,允许您动态提供 WebP 图像,在不改变图片URL路径的情况下,自动将JPEG、PNG、BMP、GIF等图像转换为WebP格式,从而减小图片体积,降低流量消耗和提高加载速度。
星哥玩云
2022/08/13
2.2K0
使用WebP Server在不改变URL的情况下将网站图像转换为WebP

相似问题

通过javascript将div内容转换为图像

22

使用Javascript将div替换为图像

40

将DIV内容替换为DIV内容JavaScript (No jQuery)

44

纯javascript方法将内容包装在div中

100

将div的内容转换为图像

30
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档