Reputation: 506
My custom infoWindows are larger than the default. This means I have to lower the point in which the map centers upon clicking a marker, so that the infoWindow will be shown fully. The problem is, since I move the map position down by a specific amount of latitude, when the map is zoomed in close, the offset is too great. Inversely, when the I zoom far out, it doesn't move down enough. How can I position the infoWindow relative to the screen height?
Default look of screen. X is anchor of infoWindow
|-----|
|-----|
|--X--|
|-----|
|-----|
What I want: (No matter the zoom level)
|-----|
|-----|
|-----|
|--X--|
|-----|
Upvotes: 3
Views: 3815
Reputation: 2970
I know its to old and somewhat completed problem but after working 4-5 hour R&D finally i am on this stage to do something different stuff.
In this scenario I Use fragment instead of infowindow for more reliability.
First of all click on below link :)
in this Guist i added 3 files
1) customeMapview..java link
this is custom mapview Use it at your xml file.
2) maps_fragment.xml link
I just put my Infowindow below at the map if you want upper side ,left side , you can set your framlayout with your perspective.make sure android:clickable="true" at your framlayout for cancle bottom map click.
3)MapsFragment.java link
first of all onMarkerClick set your fragment transition.
lets move on your customMapview's mapview.setCustomEventListener inside
if (intersects) {}
your main basic code to hide your customInfo window.
and you can set your interface at here bottom
//custome listner to fetch data from Custom map view because map does't allow anu touch/click listner
public interface OnCustomEventListener {
void onEvent(MotionEvent ev);}
Enjoy the custom static infowindow for map any question or suggetion please tell me at below comment
Upvotes: 1
Reputation: 5651
To lower the point at which the map centers on a marker can be done. Sorry but you loose the default info window implementation. Don't worry your custom info window will easily port to this method. This is a very good thing to handle onMarkerClick
because now your info window can handle buttons link to external content, anything the info windows do on the google maps application like a nav button can be done at onMarkerClick() with a popup window or dialog fragment.
Follow these steps.
mMap.setOnMarkerClickListener(this);
mMap.moveCamera(CameraUpdateFactory.newLatLng(markers newlat newlon));
return false;
from the onMarkerClick event to tell android your
handling the marker.Note return true from onMarkerClick() for markers you want to use the default map info window.
Upvotes: 2
Reputation: 1954
What I would do:
1.) Don't create/add the default InfoWindow to your marker
2.) Instead add an event handler ( OnMarkerClickListener ) to your marker
3.) In that clickhander, "compute" where you want your infowindow to appear
For example, get the
Projection projection = map.getProjection(); // get map projection
VisibleRegion vr = projection.getVisibleRegion(); //
With vr, you can get the lower-left corner coordinates of your screen. Add a few points to that corner, and you can call
LatLng infoLL = projection.fromScreenLocation(Point infoPoint);
to get the coordinates of where you want your InfoWindow to appear
4.) Create a "dummy marker" on the fly (e.g. one pixel image) such that it is invisible using the location you computed above (infoLL)
5.) Add your InfoWindow data into it
6.) Immediately call showInfoWindow() into it
7.) As an option, add an OnInfoWindowClickListener into it, to delete the dummy marker if clicked, or a delayed delete
Upvotes: 2