指标值的问题 [英] index value issue on the markers

查看:182
本文介绍了指标值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在fcmUsers列表中的标记上显示这些值。当用户点击标记时,它将在fcmUsers列表中显示它自己的值或文本视图中的数据

fcmUsers List has public Long createdat;和public Long hajjappnum;

pre $ UserName $ UserName = ( DevicesLatest);
UserRef.keepSynced(true);
new GetDataFromFirebase()。executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


FirebaseDatabase数据库= FirebaseDatabase.getInstance();

// myRef = database.getReference(GPSLocationHistory / DevicesLatest);

$ b UserRef.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
latLngList.clear();
mMap.clear();
if(marker!= null){
marker.remove();
}
Toast.makeText(MapsActivity.this,change ();
fcmUsers = new ArrayList<>();
i = new DataList();
Iterator< DataSnapshot> dataSnapshots = dataSnapshot.getChildren 0;
while(dataSnapshots.hasNext()){
DataSnapshot dataSnapshotChild = dataSnapshots.next();
ModelClassFireBase fcmUser = dataSnapshotChild.getValue(ModelClassFireBase.class);
fcmUsers。 add(fcmUser);
LatLng latLng = new LatLng(Double.parseDouble(fcmUsers.get(i).lati.toString()),Double.parseDouble(fcmUsers.get(i).longi.toString()) ); //使用你的服务器的方法
latLngList.add(的latLng);
mark1 = mMap.addMarker(new MarkerOptions()。title(fcmUsers.get(i).Battery.toString())。position(latLngList.get(i))); //。icon(BitmapDescriptorFactory.fromResource (R.drawable.female4)));
// Toast.makeText(getApplicationContext(),uniqueids.get(i).toString(),Toast.LENGTH_LONG).show();
markerList.add(mark1);


i ++;
$ b $ if(fcmUsers.size()> 0){

} else {
//显示对话框,没有用户可用。





$ b @Override
public void onCancelled(DatabaseError databaseError){
//处理数据库错误
}
});
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter(){
@Override
public View getInfoWindow(Marker arg0){
return null;
}

//定义InfoWindow的内容
@Override
public View getInfoContents(Marker arg0){

//从布局文件中获取视图info_window_layout
查看v = getLayoutInflater()。inflate(R.layout.info_widow_layout,null);

//从标记中获取位置
LatLng latLng = arg0.getPosition();

//获取引用TextView设置纬度
TextView userbattery =(TextView)v.findViewById(R.id.tv_lat);

//获取引用TextView设置经度
// TextView tvLng =(TextView)v.findViewById(R.id.tv_lng);
// ImageView userimage =(ImageView)v.findViewById(R.id.userimage);


userbattery.setText(user batter y:+ fcmUsers.get(i-1).Battery.toString());

return v;

}

});


解决方案

首先,我没有看到你需要将Arraylists存储在Firebase方法之外。我想你应该删除它们和 i 变量。

如果你确实需要列表,它们只能从 onDataChange



其次,您的标记目前只显示电池。

  new MarkerOptions()。title(fcmUsers.get(i).Battery.toString())

您可以为要显示的数据创建一个字符串变量,并将其替换。



如果你想用Marker存储整个对象,使用标签。

  final ModelClassFireBase fcmUser = dataSnapshotChild.getValue(ModelClassFireBase.class); 
Marker = mMap.addMarker(new MarkerOptions()
.title(user.getBattery())
.position(new LatLng(user.getLatitude(),user.getLongitude()) ;
mark.setTag(user);

p>

  final ModelClassFireBase user =((ModelClassFireBase)arg0).getTag(); 
userbattery.setText(user battery:你不能使用 get(i)+ user.getBattery());

在这个地方,因为那不是那个标记的实际位置


I want to display these values on markers from the fcmUsers list

when user click on marker it will show its own value or data in text view from the fcmUsers list

fcmUsers List have public Long createdat; and public Long hajjappnum;

DatabaseReference UserRef = FirebaseDatabase.getInstance().getReference().child("GPSLocationHistory").child("DevicesLatest");
UserRef.keepSynced(true);
new GetDataFromFirebase().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);


FirebaseDatabase database = FirebaseDatabase.getInstance();

//  myRef = database.getReference("GPSLocationHistory/DevicesLatest");


UserRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        latLngList.clear();
        mMap.clear();
        if (marker != null) {
            marker.remove();
        }
        Toast.makeText(MapsActivity.this, "change", Toast.LENGTH_SHORT).show();
        Iterator<DataSnapshot> dataSnapshots = dataSnapshot.getChildren().iterator();
         fcmUsers = new ArrayList<>();
         i = 0;
        while (dataSnapshots.hasNext()) {
            DataSnapshot dataSnapshotChild = dataSnapshots.next();
            ModelClassFireBase fcmUser = dataSnapshotChild.getValue(ModelClassFireBase.class);
            fcmUsers.add(fcmUser);
            LatLng latLng = new LatLng(Double.parseDouble(fcmUsers.get(i).lati.toString()), Double.parseDouble(fcmUsers.get(i).longi.toString())); // Use your server's methods
            latLngList.add(latLng);
            mark1 = mMap.addMarker(new MarkerOptions().title(fcmUsers.get(i).Battery.toString()).position(latLngList.get(i)));//.icon(BitmapDescriptorFactory.fromResource(R.drawable.female4)));
            // Toast.makeText(getApplicationContext(), uniqueids.get(i).toString(), Toast.LENGTH_LONG).show();
            markerList.add(mark1);


            i++;

            if (fcmUsers.size() > 0) {

            } else {
                // Display dialog for there is no user available.
            }

        }


    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        // for handling database error
    }
});
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
    @Override
    public View getInfoWindow(Marker arg0) {
        return null;
    }

    // Defines the contents of the InfoWindow
    @Override
    public View getInfoContents(Marker arg0) {

        // Getting view from the layout file info_window_layout
        View v = getLayoutInflater().inflate(R.layout.info_widow_layout, null);

        // Getting the position from the marker
        LatLng latLng = arg0.getPosition();

        // Getting reference to the TextView to set latitude
        TextView userbattery = (TextView) v.findViewById(R.id.tv_lat);

        // Getting reference to the TextView to set longitude
       // TextView tvLng = (TextView) v.findViewById(R.id.tv_lng);
       // ImageView userimage = (ImageView) v.findViewById(R.id.userimage);


        userbattery.setText("user battery:" + fcmUsers.get(i-1).Battery.toString());

        return v;

    }

});

解决方案

Firstly, I don't see a reason why you need to store Arraylists off of the Firebase method. I think you should remove them and the i variable.

If you do need lists, they should only be initialized starting at onDataChange

Secondly, your marker currently only displays the battery.

new MarkerOptions().title(fcmUsers.get(i).Battery.toString())

You can make a String variable of the data you want to show, and replace that.


If you want to store the entire object with the Marker, use tags.

final ModelClassFireBase fcmUser = dataSnapshotChild.getValue(ModelClassFireBase.class);
Marker mark = mMap.addMarker(new MarkerOptions()
    .title(user.getBattery())
    .position(new LatLng(user.getLatitude(), user.getLongitude());
mark.setTag(user);

And down below, get the tag

final ModelClassFireBase user = ((ModelClassFireBase) arg0).getTag();
userbattery.setText("user battery:" + user.getBattery());

You cannot use get(i) in this place because that is not the actual position of that marker

这篇关于指标值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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