1

Currently I have a Custom infowindow. When I click on it it will open a new activity. I want to animate the transaction and to do so I need the position of the infowindow on the screen. Since the infowindow is drawn in the screen using canvas I can't work with the infowindow view to get its position. Is there any workarround to archive this?

Thanks

public View getInfoWindow(Marker marker) {
    if (mCurrentMarker != null && !mCurrentMarker.isInfoWindowShown() && mCurrentMarkerView != null && marker.equals(mCurrentMarker))
        return mCurrentMarkerView;
    mCurrentMarker = marker;
    mCurrentMarkerView = getActivity().getLayoutInflater().inflate(R.layout.listing_infowindow, null);
    if (marker.getTitle() == null)
        return null;
    String[] data = marker.getTitle().split("@@@");
    ((TextView) mCurrentMarkerView.findViewById(R.id.infoText)).setText(data[0]);
    mCurrentMarkerView.findViewById(R.id.infoText).setTag(data[1]);
    ((TextView) mCurrentMarkerView.findViewById(R.id.infoDescription)).setText(marker.getSnippet());
    final ImageView img = (ImageView) mCurrentMarkerView.findViewById(R.id.infoIcon);
    String image;
    if (data.length < 3)
        image = "";
    else
        image = data[2];
    ImageLoader.getInstance().displayImage(image, img, new DisplayImageOptions.Builder()
             .showImageOnLoading(R.drawable.nopic)
             .showImageOnFail(R.drawable.nopic)
             .cacheInMemory(false)
             .cacheOnDisk(false)
             .considerExifParams(true)
             .build(), new SimpleImageLoadingListener() {
        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            super.onLoadingComplete(imageUri, view, loadedImage);

            if (mCurrentMarker != null && mCurrentMarker.isInfoWindowShown()) {
                mCurrentMarker.hideInfoWindow();
                mCurrentMarker.showInfoWindow();
            }

        }
    });

    return mCurrentMarkerView;

}
Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
  • Hello Pedro can you show us some code so we can help? – PedroAGSantos Jul 28 '14 at 11:25
  • I don't see how that can help. What code you need? The getInfoWindow is quite a large piece of code. Other than that the code has nothing too special. I'm using Google Maps Clustering and I show the new activity on the event onClusterItemInfoWindowClick. – Pedro Oliveira Jul 28 '14 at 11:31
  • show us how you create getInfoWindow. – PedroAGSantos Jul 28 '14 at 11:33
  • Edited. Still don't know how that piece of code is going to help since after the return of the method the map will call canvas.draw and draw the view on the map. It will be an image instead of a View. – Pedro Oliveira Jul 28 '14 at 11:37
  • you can get a position of marker like marker.getPosition() also take a look at http://stackoverflow.com/questions/14429877/how-to-get-screen-coordinates-from-marker-in-google-maps-v2-android – PedroAGSantos Jul 28 '14 at 11:43
  • Yeah you're right. But you forgot that that's the position in the map (LatLng). And as you can see in the title I want the screen position (Left and Top) – Pedro Oliveira Jul 28 '14 at 11:46
  • hope it works check my answer – PedroAGSantos Jul 28 '14 at 11:54

1 Answers1

1
Projection projection = map.getProjection();

LatLng markerLocation = marker.getPosition();

Point screenPosition = projection.toScreenLocation(markerLocation);
PedroAGSantos
  • 2,336
  • 2
  • 17
  • 34
  • Yeap it works. It's the marker position and I wanted the infowindow but that's close enough. A bit more math and I can get it working. thanks – Pedro Oliveira Jul 28 '14 at 12:00