UPDATE 07/12/2011: I figured it out. Will post solution as soon as I'm finished with the implementation.

I am creating an Android application that will display the location of several users on a Google Map. The users are currently represented as blue and green dots on the map. When you tap the blue dot representing your location, a custom overlay appears on the map that says "Current Location"

http://imgur.com/7S1Bg

My problem is that when I scroll or zoom the map the overlay with "Current Location" remains in the same spot while the map moves below it. I want it to move with the map so that the popup is always directly above the blue dot, like in this example:

http://econym.org.uk/gmap/example_ewindow.htm.

Here is how my map project is laid out:

I have an Activity that extends com.google.android.maps.MapActivity. This activity has as a member a com.google.android.maps.MapView object. I manage the overlays with an AdjacentMapOverlayList (which extends ItemizedOverlay).

Here is my code when a user clicks on the blue icon:

/*
 * Handle tap events.
 * 
 * @param index the item that was tapped
 */
@Override
protected boolean onTap(int index) {

    Log.d(TAG, "User clicked something");

    // get the item that was tapped
    OverlayItem item = (OverlayItem) getItem(index);

    // cast it
    AdjacentUserOverlay overlay = (AdjacentUserOverlay) item;

    // get the point from the item
    GeoPoint geo = overlay.getPoint();
    Point pt = m_mapView.getProjection().toPixels(geo, null);

    // display the dialog
    m_userPopupDialog.show(pt.x, pt.y);

    // true dat
    return true;
}

I am guessing that I need to intercept map movement events and move the popup dialogs manually, but there has to be an easier way. Can anyone explain how to do this? I'll be on all day if you need any additional information. Thanks for any advice!

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top