Added a marker to the map along with some informative window.
Marker marker = map.addMarker(new MarkerOptions() .position(new LatLng(47.045029, 28.861427)) .title("Marker") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)) .snippet("Population: 4,137,400")); Implemented in InfoWindow when you click a button on which you can click. How can I add the ability to call by clicking on a certain number (for each marker has its own number)?
Map class:
@Override public void onMapReady(GoogleMap map) { map.getUiSettings().setZoomControlsEnabled(true); LatLngBounds.Builder builder = new LatLngBounds.Builder(); //final MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(map); MapWrapperLayout mapWrapperLayout = (MapWrapperLayout) findViewById(R.id.map_relative_layout); //final GoogleMap map = mapFragment.getMap(); // MapWrapperLayout initialization // 39 - default marker height // 20 - offset between the default InfoWindow bottom edge and it's content bottom edge mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); // We want to reuse the info window for all the markers, // so let's create only one class member instance this.infoWindow = (ViewGroup) getLayoutInflater().inflate(R.layout.info_window, null); this.infoTitle = (TextView) infoWindow.findViewById(R.id.title); this.infoSnippet = (TextView) infoWindow.findViewById(R.id.snippet); this.infoButton = (Button) infoWindow.findViewById(R.id.button); // Setting custom OnTouchListener which deals with the pressed state // so it shows up this.infoButtonListener = new OnInfoWindowElemTouchListener(infoButton, getResources().getDrawable(R.drawable.round_but_green_sel), //btn_default_normal_holo_light getResources().getDrawable(R.drawable.round_but_red_sel)) //btn_default_pressed_holo_light { @Override protected void onClickConfirmed(View v, Marker marker) { // Here we can perform some action triggered after clicking the button Toast.makeText(MapsActivity.this, marker.getTitle() + "'s button clicked!", Toast.LENGTH_SHORT).show(); } }; this.infoButton.setOnTouchListener(infoButtonListener); map.setInfoWindowAdapter(new InfoWindowAdapter() { @Override public View getInfoWindow(Marker marker) { return null; } @Override public View getInfoContents(Marker marker) { // Setting up the infoWindow with current's marker info infoTitle.setText(marker.getTitle()); infoSnippet.setText(marker.getSnippet()); infoButtonListener.setMarker(marker); mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow); return infoWindow; } }); Marker marker = map.addMarker(new MarkerOptions() .position(new LatLng(47.045029, 28.861427)) .title("Marker") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)) .snippet("Population: 4,137,400")); Marker marker2 = map.addMarker(new MarkerOptions() .position(new LatLng(47.000327, 28.867950)) .title("Marker") .snippet("Population: 4,137,400")) builder.include(marker.getPosition()); builder.include(marker2.getPosition()); LatLngBounds bounds = builder.build(); int padding = 150; // offset from edges of the map in pixels CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); map.moveCamera(cu); } The OnInfoWindowElemTouchListener class:
public abstract class OnInfoWindowElemTouchListener implements OnTouchListener { private final View view; private final Drawable bgDrawableNormal; private final Drawable bgDrawablePressed; private final Handler handler = new Handler(); private Marker marker; private boolean pressed = false; public OnInfoWindowElemTouchListener(View view, Drawable bgDrawableNormal, Drawable bgDrawablePressed) { this.view = view; this.bgDrawableNormal = bgDrawableNormal; this.bgDrawablePressed = bgDrawablePressed; } public void setMarker(Marker marker) { this.marker = marker; } @Override public boolean onTouch(View vv, MotionEvent event) { if (0 <= event.getX() && event.getX() <= view.getWidth() && 0 <= event.getY() && event.getY() <= view.getHeight()) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: startPress(); break; // We need to delay releasing of the view a little so it shows the // pressed state on the screen case MotionEvent.ACTION_UP: handler.postDelayed(confirmClickRunnable, 150); break; case MotionEvent.ACTION_CANCEL: endPress(); break; default: break; } } else { // If the touch goes outside of the view's area // (like when moving finger out of the pressed button) // just release the press endPress(); } return false; } private void startPress() { if (!pressed) { pressed = true; handler.removeCallbacks(confirmClickRunnable); view.setBackgroundDrawable(bgDrawablePressed); if (marker != null) marker.showInfoWindow(); } } private boolean endPress() { if (pressed) { this.pressed = false; handler.removeCallbacks(confirmClickRunnable); view.setBackgroundDrawable(bgDrawableNormal); if (marker != null) marker.showInfoWindow(); return true; } else return false; } private final Runnable confirmClickRunnable = new Runnable() { public void run() { if (endPress()) { onClickConfirmed(view, marker); } } }; /** * This is called after a successful click */ protected abstract void onClickConfirmed(View v, Marker marker); }