Search code examples
google-mapsgoogle-maps-api-3google-maps-markersgoogle-geocodergoogle-geocoding-api

Is it possible to check Latitude and Longitude is inside the viewport [drawn shape] or not [AT SERVER SIDE]


In Javascript (Client side), I could find out whether the given latitude and longitude is inside or outside the drawn shape by the contains method of google.maps.LatLngBounds class.

On the server side, is it possible to check whether the given coordinate is inside or outside the shape?


Solution

  • I believe you do not need any function to check it out. Simple logic could do that.

    Please try out the logic below.

    FOR RECTANGLE

    public void rectangleRegionChecker() {
        double Given_Lattitude;
        double Given_Longtitude;
        double SouthWestLattitude;
        double SouthWestLongtitude;
        double NorthEastLattitude;
        double NorthEastLongitude;
        if((SouthWestLattitude<=Given_lattitude)&&(SouthWestLongtitude<=Given_Longtitude)&&(NorthEastLattitude>=Given_Lattitude)&&(NorthEastLongtitude>=Given_Longtitude)){
        S.O.P("Inside the Rectangle");
        }
    }
    

    I believe this will help you a lot.