According to this
http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinate(v=vs.110).aspx
The longitude can range from -180.0
to 180.0
; so you have to be accurate with -180/180
since -180
logitude is equal to 180
one; just imagine a rectangle
(15, 178, 25, -178)
the point (20, 179)
should be within the rectangle and (20, 177)
should be not; that's why RectangleF.Contains()
could be incorrect in some cases;
// Just to show the idea with 180 latitude;
// First 4 parameters could be crammed into RectangleF
// And last 2 parameters into PointF
public static Boolean WithinRectangle(Double latitudeNorth,
Double longitudeWest,
Double latitudeSouth,
Double longitudeEast,
Double latitude,
Double longitude) {
if (latitude > latitudeNorth)
return false;
else if (latitude < latitudeSouth)
return false;
if (longitudeEast >= longitudeWest)
return ((longitude >= longitudeWest) && (longitude <= longitudeEast))
else
return (longitude >= longitudeWest) || (longitude <= longitudeEast);
return false;
}