Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to: validate Location's latitude and longitude values

Tags:

android

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)

like image 766
eros Avatar asked Sep 09 '11 01:09

eros


1 Answers

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

like image 176
Arun Avatar answered Oct 10 '22 23:10

Arun