Help us translate this website and improve this translation and earn free licenses!
Anonymous user  |  Log in  |  Create Account

How to...

GLatLngBounds

GLatLngBounds represents a rectangle within the map, marked by the ends southwest (sw) and northeast (ne).

GLatLngBounds has several methods that can be extremely useful to conduct some operations with our maps:
  • equals(GLatLngBounds): tells us if the GLatLngBounds passed as parameter is equal to the one of the rectangle
  • contains(GLatLng): tells us if the GLatLng passed as parameter is within the actual rectangle.
  • intersects(GLatLngBounds): tells us if the rectangle passed as parameter intersects the rectangle
  • containsBounds(GLatLngBounds): it tells us if the passed rectangle as parameter contains the rectangle.
  • extend(GLatLng): expands the rectangle so that the GLatLng is left within it.
  • getSouthWest: gives back the GLatLng that corresponds to the southwestern coordinate.
  • getNorthEast: gives back the GLatLng that corresponds to the northwestern coordinate.
  • toSpan: gives back the GLatLng that represents the coordinates of the rectangle.
  • isFullLat: tells us if the rectangle extends from the South Pole to the North Pole
  • isFullLng: Tells us if the rectangle extends throughout all earth longitude.
  • isEmpty: tells us if the rectangle is empty.
  • getCenter: gives back the central coordinate of the rectangle.
Furthemore, with the static method GMap1.getBoundsZoomLevel(latlngbounds) we obtain the biggest zoom from which we can see the area defined by the latlngbounds.



Code.aspx.cs
GLatLng sw = new GLatLng(40, 15);
GLatLng ne = sw + new GLatLng(5, -10.2);
GLatLngBounds latlngbounds = new GLatLngBounds(sw, ne);

GMap1.addGMarker(new GMarker(latlngbounds.getNorthEast()));
GMap1.addGMarker(new GMarker(latlngbounds.getSouthWest()));

GMap1.GZoom = GMap1.getBoundsZoomLevel(latlngbounds);
GMap1.setCenter(latlngbounds.getCenter());

GLatLng sw2 = new GLatLng(42, 7);
GLatLng ne2 = sw2 + new GLatLng(5, 5);
GLatLngBounds latlngbounds2 = new GLatLngBounds(sw2, ne2);

GLatLng swBig = new GLatLng(35, 0);
GLatLng neBig = swBig + new GLatLng(15, 15);
GLatLngBounds latlngboundsBig = new GLatLngBounds(swBig, neBig);

GLatLng inside = latlngbounds.getCenter();
GLatLng outside = neBig + new GLatLng(10, 10);

bool isInside = latlngbounds.contains(inside);
bool isOutSide = !latlngbounds.contains(outside);
bool intersect = latlngbounds.insersects(latlngbounds2);
bool contains = latlngboundsBig.containsBounds(latlngbounds);

Powered by Subgurim.NET