How do you validate Location? seems that setting it to these values Location.setLatitude(999) & Location.setLongitude(999) are valid (means there's no any validation). Is there a Android way to validate it? (i know the maximum and minimum values of it but just wondering if there's already available using Android)
Here is the simple function that validates latitude and longitude
public boolean isValidLatLng(double lat, double lng){
if(lat < -90 || lat > 90)
{
return false;
}
else if(lng < -180 || lng > 180)
{
return false;
}
return true;
}
Latitude measures how far north or south of the equator a place is located. The equator is situated at 0°, the North Pole at 90° north (or 90°, because a positive latitude implies north), and the South Pole at 90° south (or –90°). Latitude measurements range from 0° to (+/–)90°.
Longitude measures how far east or west of the prime meridian a place is located. The prime meridian runs through Greenwich, England. Longitude measurements range from 0° to (+/–)180°.
Reference taken from https://msdn.microsoft.com/en-us/library/aa578799.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With