Get Data(title)From Info-Window of Marker 并放入对话框

Get Data(title)From Info-Window of Marker and Put on Dialog Box

我创建了 MapView,其中我使用从 Firestore 数据库调用的经度和纬度在地图上绘制标记。 并且还检索 Info-window 上的职位名称作为标题,但现在我已经创建了对话框,我想在其中显示标题名称,该名称位于他的标记的信息窗口中 所以我该怎么做?? 请分享你的答案

这是我的Java代码

@Override
public void onMapReady(final GoogleMap googleMap) {

    mGoogleMap = googleMap;

    FirebaseFirestore mDatabase = FirebaseFirestore.getInstance();
    CollectionReference mOrderRef = mDatabase.collection("Job Post1");

    mOrderRef.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
        @Override
        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
            for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                if (documentSnapshot.contains("lat") && documentSnapshot.contains("lon")) {
                    String lat = (String) documentSnapshot.get("lat");
                    String lon = (String) documentSnapshot.get("lon");
                    final String title = (String) documentSnapshot.get("title");

                    if (lat != null && lon != null && !lat.isEmpty() && !lon.isEmpty()) {
                        double latitude = Double.parseDouble(lat.trim());
                        double longitude = Double.parseDouble(lon.trim());
                        googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(title));
                        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12.0f));

                        googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
                            @Override
                            public void onInfoWindowClick(Marker marker) {
                                Jobpost jobpost = new Jobpost();
                                TextView txtclose, textView26;
                                myDialog.setContentView(R.layout.custompopup);
                                txtclose = (TextView) myDialog.findViewById(R.id.txtclose);
                                textView26 = (TextView) myDialog.findViewById(R.id.textView26);
                                txtclose.setText("X");
                                txtclose.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        myDialog.dismiss();
                                    }
                                });
                                Intent intent = getActivity().getIntent();

                                myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                                myDialog.show();
                            }
                        });

                    }

                }
            }

        }

    });
}

单击标记的信息窗口时打开对话框

您可以使用 marker 找到您在 addMarker 期间设置的 title。检查以下内容:

googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {
        new AlertDialog.Builder(TestActivity.this)
                .setTitle(marker.getTitle())
                .setMessage(marker.getPosition().latitude + " -> " + marker.getPosition().longitude)
                .setPositiveButton("OK", null)
                .create().show();
    }
});

输出: