GoogleMap.InfoWindowAdapter详细信息,&折线

时间:2017-07-17 03:26:10

标签: android google-maps google-maps-markers

我想在loc.setText上获取list_location.get(i).getLatitude()问题是它循环并获取最后一个纬度,添加按钮问题解除不起作用以及如何点击后在每个标记上添加折线按钮?

这是我的代码:

     b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (i = 0; i < list_location.size(); i++) {
                    createMarker(i, list_location.get(i).getLatitude(), list_location.get(i).getLongitude(), list_location.get(i).getLocation());
                }
            }
            });
        return v;
    }

    private void createMarker(int index, String latitude, String longitude, String snippet) {
        // Adding the taped point to the ArrayList
        BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.ic_menu_camera);
        Double lat = Double.parseDouble(latitude);
        Double Longitude = Double.parseDouble(longitude);

/*        float color = 0;
        if (index == 1)
            color = BitmapDescriptorFactory.HUE_AZURE;
        else if (index == list_location.size()-1)
            color = BitmapDescriptorFactory.HUE_VIOLET;*/

        if (index == 1)
            image = BitmapDescriptorFactory.fromResource(R.drawable.ic_menu_gallery);
        else if (index == list_location.size()-1)
            image = BitmapDescriptorFactory.fromResource(R.drawable.ic_menu_slideshow);
        else {
            image = BitmapDescriptorFactory.fromResource(R.drawable.ic_menu_camera);
        }

        map.addMarker(new MarkerOptions()
                .position(new LatLng(lat, Longitude))
                .anchor(0.5f, 0.5f)
                .title("title")
                .snippet(list_location.get(i).getLatitude())
                .icon(image));

        map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker arg0) {
                return null;
            }
            @Override
            public View getInfoContents(Marker marker) {

                LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
                View myContentView = inflater.inflate(R.layout.marker_popup, null);
                TextView loc = ((TextView) myContentView
                        .findViewById(R.id.textView2));
                TextView plate_num = ((TextView) myContentView
                        .findViewById(R.id.textView4));
                loc.setText(marker.getTitle());
                plate_num.setText(marker.getSnippet());
/*                for (int i = 0; i < list_location.size(); i++) {
                    Log.d("TAG", "getLatitude:" + list_location.get(i).getLatitude() + " getLongitude:" + list_location.get(i).getLongitude());
                    if (marker.getSnippet().equals(list_location.get(i).getLocation())) {
                        Log.d("TAG", "Selected Marker");
                    }

                }*/

                Button btnDismiss = (Button) myContentView.findViewById(R.id.button2);
                btnDismiss.setOnClickListener(new Button.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        popupWindow.dismiss();
                    }
                });
                return myContentView;
            }
        });

0 个答案:

没有答案