Android Marker Click Function
我正在寻找一种在单击标记的信息框/片段时运行的方法。到目前为止,我找不到任何关于此的信息,只有标记。关于在哪里可以找到更多信息的任何帮助或链接?
要创建在单击信息窗口时运行的方法,您需要
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | map.setInfoWindowAdapter(new InfoWindowAdapter() { // Use default InfoWindow frame @Override public View getInfoWindow(Marker args) { return null; } // Defines the contents of the InfoWindow @Override public View getInfoContents(Marker args) { // Getting view from the layout file info_window_layout View v = getLayoutInflater().inflate(R.layout.info_window_layout, null); // Getting the position from the marker clickMarkerLatLng = args.getPosition(); TextView title = (TextView) v.findViewById(R.id.tvTitle); title.setText(args.getTitle()); map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { public void onInfoWindowClick(Marker marker) { if (SGTasksListAppObj.getInstance().currentUserLocation!=null) { if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8))) { Toast.makeText(getApplicationContext(),"This your current location, navigation is not needed.", Toast.LENGTH_SHORT).show(); } else { FlurryAgent.onEvent("Start navigation window was clicked from daily map"); tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository(); for (Task tmptask : tasksRepository) { String tempTaskLat = String.valueOf(tmptask.getLatitude()); String tempTaskLng = String.valueOf(tmptask.getLongtitude()); Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)); if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8))) { task = tmptask; break; } } Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class); intent.putExtra(TasksListActivity.KEY_ID, task.getId()); startActivity(intent); } } else { Toast.makeText(getApplicationContext(),"Your current location could not be found,\ Navigation is not possible.", Toast.LENGTH_SHORT).show(); } } }); |
只需为您的地图设置 OnInfoWindowClickListener。
1 2 3 4 5 6 | map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { //YOUR CODE } }); |