获取android系统地图V2 PopupClick事件的自定义类数据信息自定义、事件、地图、数据

2023-09-07 09:58:59 作者:爱过贱人ソ信过狗

朋友你好我的Java文件,如下

hello friends my java file as below

public class MainActivity extends FragmentActivity {

GoogleMap googleMap;

final int RQS_GooglePlayServices = 1;
Double lat;
Double lng;
Marker marker;
LatLng coordinate;
private LocationManager locationManager;
private String provider;
Marker startPerc;
AutoCompleteTextView mAutoCompleteTextViewAddress;
CommonMethods mCommonMethods;
String getsearchingAddress;

Geocoder mGeocoder;
List<Address> list;
int maxResult = 10;
String addressList[];
Intent mIntent;

public double latitude;
public double longitude;
private HashMap<String, String> eventMarkerMap;

LatLng mLatLng;

public static double CurrentLatitude;
public static double CurrentLongitude;
DatabaseConnectionAPI mDatabaseConnectionAPI;
ArrayList<ParserRestaurant> mArrayListRestaurent;
ArrayList<ParserBranch> mArrayListBranch;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mCommonMethods = new CommonMethods();
    // initilizeMap();
    mDatabaseConnectionAPI = new DatabaseConnectionAPI(
            getApplicationContext());
    try {
        mDatabaseConnectionAPI.createDataBase();
        mDatabaseConnectionAPI.openDataBase();
    } catch (IOException e) {
        e.printStackTrace();
    }

    mArrayListBranch = new ArrayList<ParserBranch>();
    mArrayListBranch = mDatabaseConnectionAPI.getBranchData();


    if (googleMap == null) {
        googleMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        if (googleMap == null) {
            // Toast.makeText(getApplicationContext(),
            // "Sorry! unable to create maps", Toast.LENGTH_SHORT).show();
        }
    }

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

        ParserBranch mBranch=new ParserBranch();
        mBranch.setBrId(mArrayListBranch.get(i).getBrId());
        LatLng coordinate = new LatLng(Double.parseDouble(mArrayListBranch
                .get(i).getBrLat()), Double.parseDouble(mArrayListBranch
                .get(i).getBrLng()));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(Double.parseDouble(mArrayListBranch.get(i)
                        .getBrLat()), Double.parseDouble(mArrayListBranch
                        .get(i).getBrLng())), 8.0f));
        Marker startPerc = googleMap
                .addMarker(new MarkerOptions()
                        .position(coordinate)
                        .title(mArrayListBranch.get(i).getResName())
                        .snippet(mArrayListBranch.get(i).getAddress())
                        .icon(BitmapDescriptorFactory
                                .defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
        eventMarkerMap = new HashMap<String, String>();
        System.out.println("fd " + mArrayListBranch.get(i).getBrId());
        System.out.println("Marker ID "+startPerc.getId());
        eventMarkerMap.put(startPerc.getId(), mArrayListBranch.get(i).getBrId());
    }

    googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {

            String eventInfo = eventMarkerMap.get(marker);
            System.out.println("ID " + eventInfo);
            marker.hideInfoWindow();

        }
    });

    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker marker) {

            return null;
        }

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

            // Getting view from the layout file info_window_layout

            View v = getLayoutInflater().inflate(R.layout.row_map, null);

            // Getting reference to the TextView to set title
            TextView note = (TextView) v.findViewById(R.id.txt_name);
            TextView snip = (TextView) v.findViewById(R.id.txt_snip);
            note.setText(marker.getTitle());
            snip.setText(marker.getSnippet());
            // Returning the view containing InfoWindow contents
            return v;

        }

    });


}

在我上面code运行多个引脚下降onmap,但我希望得到特定标记的信息,当我上标记点击,所以我采取setOnInfoWindowClickListener对于和打印值,如果particlur标记ID,但它给了我每一次空任何想法我怎么能解决呢?

when i run above code multiple pin is drop onmap but i want to get particular marker information when i click on that marker so i take setOnInfoWindowClickListener for that and print value if particlur marker id but it gave me every time null any idea how can i solve it ?

推荐答案

您是把标记ID作为地图键:

You are putting marker id as a map key:

eventMarkerMap.put(startPerc.getId(), mArrayListBranch.get(i).getBrId());

但您尝试使用检索你的价值标记对象:

but you are trying to retrieve your value using marker object:

String eventInfo = eventMarkerMap.get(marker);