如何在折线点击中获取特定数据? [英] How to get the specific data in click of polyline?

查看:76
本文介绍了如何在折线点击中获取特定数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有多个数据的时候,我正在绘制经纬度和经度值的折线.现在,当我绘制它时,我要指定线段还因为单击折线的时间现在应该有所不同,因为也许纬度和经度值会相同,但是有些时候我会给定特定值,那么我可以知道点击的时间长短.

At the time of multiple data with the help of that I am plotting the polyline with lat and long value. Now when I'm plotting it, I'm to specific the line also because that the time of polyline click I should now the different because maybe the lat and long value will same but some when I will give specific value to that then I can know which lat and long is been click.

PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.addAll(coordinateList);
polylineOptions.width(10);
polylineOptions.color(Color.parseColor("#800080"));
Polyline line = mMap.addPolyline(polylineOptions);
line.setClickable(true);

coordinateList是lat和long值的列表.但是我想添加一个特定的值以在单击它时获得该值.

coordinateList is the list of lat and long value. But I want to add one specific value to get the the value when it is been clicked.

@Override
public void onPolylineClick(Polyline polyline) {
  double latitude = polyline.getPoints().get(0).latitude;
  double longitude = polyline.getPoints().get(0).longitude;
}

在单击中,我开始了解经纬度

In click I've come to know the lat and long

如何设置特定的值以及如何获得点击?

How I can set specific value and how I will get on click?

推荐答案

您可以维护一个结构(例如Map)来存储与Polyline关联的数据.例如(为每个Polyline存储一个String):

You can maintain a structure (a Map for example) to store the data associated to the Polylines. For example (storing a String for each Polyline):

final Map<Polyline, String> polylines = new HashMap<>();

PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.addAll(coordinateList);
polylineOptions.width(10);
polylineOptions.color(Color.parseColor("#800080"));
polylineOptions.clickable(true);

polylines.put(mMap.addPolyline(polylineOptions), "Polyline data");

mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
    @Override
    public void onPolylineClick(Polyline polyline) {
        Toast.makeText(MapsActivity.this, polylines.get(polyline), Toast.LENGTH_SHORT).show();
    }
});

这篇关于如何在折线点击中获取特定数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆