机器人地图 - 检查中心相机是否在边界内

Androids map - Check if center camera is within bounds

我想创建一种方法来查看相机坐标的中心是否在某个区域的边界内,如果是,则执行一些操作。

当我尝试此操作时出现错误:Operator ! cannot be applied to LatLngBounds

我也试过if(temp != new LatLngBounds(bounds1, bounds2))但得到了同样的错误。

这是我的方法

public GoogleMap.OnCameraChangeListener getCameraChangeListener()
{
    return new GoogleMap.OnCameraChangeListener()
    {
        @Override
        public void onCameraChange(CameraPosition cameraPosition)
        {
            LatLng temp = new LatLng(cameraPosition.target.latitude, cameraPosition.target.longitude);

            //Northwest corner of bounds
            LatLng bounds1 = new LatLng(-41.467668522, 173.03190229); 

            //Southwest corner of bounds 
            LatLng bounds2 = new LatLng(-40.095127348, 177.97574994);

            LatLngBounds outside = new LatLngBounds(bounds1, bounds2);

            //If the camera is within the bounds
            if(temp != outside)
            { 
               //do something
            }
        }
    };
}

我想你说的是东北不是西北?否则它只是一条线。

LatLngBounds 有一个 Contains 方法允许

if (outside.contains(temp){
    //do something
}

虽然 Outside 是该变量的一个误导性名称。