Show Popup Above Map Marker in Mapview

Show popup above map marker in MapView

The way I did is:

Put the markers at required GeoPoints by subclassing ItemizedOverlay, as described in http://developer.android.com/guide/tutorials/views/hello-mapview.html

Create a popup View by inflating from the layout:

View popUp = getLayoutInflater().inflate(R.layout.map_popup, map, false);

Use MapView.LayoutParams to position the popup with respect to GeoPoint in the ItemizedOverlay< OverlayItem >::onTap method. Popup will scroll automatically (without any additional code) when user scrolls the map. Basically popup gets tied to a GeoPoint, if user zooms, popup's position gets adjusted automatically.

MapView map = (MapView) findViewById(R.id.mapview);   
MapView.LayoutParams mapParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
<geopoint>,
<x offset if required>,
<y offset like pinHeight>,
MapView.LayoutParams.BOTTOM_CENTER);
map.addView(popUp, mapParams);

How to open a phoning pop up on clicking a maps marker in android?

I finally resolved it by showing the contacts that have a phone number registered :

    gMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker arg0) {

Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); // Show user only contacts with phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);

return true;

}
});

How to show a balloon above a marker in a MapActivity? Isn't there a widget?

Here is the "the missing widget"...

alt text

  • Balloons without icons:
    https://github.com/jgilfelt/android-mapviewballoons#readme

  • Balloons with icons (extends Jeff
    Gilfelt's project):
    https://github.com/galex/android-mapviewballoons (Offline, see comments to this answer)

Popup or layout over marker Android

Define some variables to save last used marker and popupView

private Marker mMarker;
private PopupWindow mPopupWindow;
private int mWidth;
private int mHeight;

In our onMarkerClick:

@Override
public boolean onMarkerClick(Marker marker) {
if (mPopupWindow != null) {
mPopupWindow.dismiss();
}
View popupView;// inflate our view here
PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
popupView.measure(size.x, size.y);

mWidth = popupView.getMeasuredWidth();
mHeight = mPopupView.getMeasuredHeight();
mMarker = marker;
mPopupWindow = popupWindow;

updatePopup();

return true;
}

updatePopup method:

private void updatePopup() {
if (mMarker != null && mPopupWindow != null) {
// marker is visible
if (mMap.getProjection().getVisibleRegion().latLngBounds.contains(mMarker.getPosition())) {
if (!mPopupWindow.isShowing()) {
mPopupWindow.showAtLocation(getView(), Gravity.NO_GRAVITY, 0, 0);
}
Point p = mMap.getProjection().toScreenLocation(mMarker.getPosition());
mPopupWindow.update(p.x - mPopupWidth / 2, p.y - mPopupHeight + 100, -1, -1);
} else { // marker outside screen
mPopupWindow.dismiss();
}
}
}

We need CameraChangeListener:

mMap.setOnCameraChangeListener(this);

@Override
public void onCameraChange(CameraPosition cameraPosition) {
...
updatePopup();
}

How to show an info window on tapping a marker on map?

Try this, modify according to your requirement:

@SuppressWarnings({ "deprecation" })
@Override
protected boolean onTap(int index)
{
CustomView customView=new CustomView(MyMap.this);
absMap.removeAllViews();
absMap.addView(customView);
customView.setBackgroundResource(R.drawable.maplocation1);
customView.setVisibility(View.INVISIBLE);

customView.removeAllViews();

absMap.invalidate();
customView.bringToFront();
customView.setVisibility(View.VISIBLE);
TextView tv2=new TextView(MyMap.this);
// tv2.setText(overlayItemList.get(index).getTitle());
tv2.setWidth(170);
tv2.setSingleLine(true);
tv2.setEllipsize(TruncateAt.END);
tv2.setSingleLine(true);
tv2.setSingleLine();

tv2.setTextColor(Color.WHITE);
tv2.setTextSize(14);
tv2.setTypeface(Typeface.DEFAULT_BOLD);

TextView tv1=new TextView(MyMap.this);
tv1.setSingleLine();
tv1.setWidth(170);
tv1.setSingleLine(true);
tv1.setEllipsize(TruncateAt.END);
tv1.setSingleLine(true);
tv2.setText(overlayItemList.get(index).getSnippet());

tv1.setTextColor(Color.WHITE);
tv1.setTextSize(12);
tv1.setTypeface(Typeface.DEFAULT_BOLD);
customView.setTag(overlayItemList.get(index).getTitle());
customView.addView(tv2, new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,10,5));
customView.addView(tv1, new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,10,25));
customView.setLayoutParams(new MapView.LayoutParams( 250, 100, overlayItemList.get(index).getPoint(),-125,-137, MapView.LayoutParams.MODE_MAP|MapView.LayoutParams.TOP_LEFT));
customView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v)
{
}
});

}


Related Topics



Leave a reply



Submit