Change infowindow position according to move right and left side map

家住魔仙堡 提交于 2020-03-23 06:50:12

问题


I have set two infowindow for pickup and drop location. I want to change info window postion like uber in the below images,

Below code is what I have tried :

@Override
public void onCameraIdle() {

//get marker position
    Projection projection = googleMap.getProjection();
    LatLng markerLocation = null;
    LatLng dropMarkerLocation=null;
    try {
        if (Marker != null) {
            markerLocation = Marker.getPosition();
        } else {
            markerLocation = new LatLng(0.0f, 0.0f);
        }
        if (MarkerDrop != null) {
            dropMarkerLocation = MarkerDrop.getPosition();
        } else {
            dropMarkerLocation = new LatLng(0.0f, 0.0f);
        }
        Point screenPosition = projection.toScreenLocation(markerLocation);
        Point screenPositiondrop = projection.toScreenLocation(dropMarkerLocation);

        final View mapview = mapFragment.getView();
        float maxX = mapview.getMeasuredWidth();
        float maxY = mapview.getMeasuredHeight();

        //Maximum visible region from x and y axis
        float x = 0.0f;
        float y = 0.0f;


//help of marker postion change infowindow position
  if (Marker != null) {

                    if (screenPosition.x> 100 && screenPosition.x + 160 > maxX) {
                       //infowindow leftside move
                    } else {
                        //infowindow rightside move
                    }
                }
                if (MarkerDrop != null) {
                    if (screenPositiondrop.x < 100 && screenPositiondrop.x + 80 < maxX) {
                      //infowindow leftside move
                    } else {
                       //infowindow rightside move
                    }
                }

    }catch (Exception e){
        e.printStackTrace();
    }
}

How can I achieve this exactly like uber?

来源:https://stackoverflow.com/questions/49687075/change-infowindow-position-according-to-move-right-and-left-side-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!