Mustapha George
Mustapha George

Reputation: 2527

google maps - test that a point is valid

How can I test that point is properly created if I cannot control that lat and lon are valid values? Is there a method that can test that point is valid?

var point = new google.maps.LatLng(lat, lon);               

Upvotes: 0

Views: 87

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117314

lat and lon must be numbers, valid ranges are:

  • latitude(approximately): -85 to 85
  • longitude:-180 to 180

So you may check the values e.g. via:

if(!isNaN(lat) && Math.abs(lat)<=85){/*valid latitude*/}
if(!isNaN(lon) && Math.abs(lon)<=180){/*valid longitude*/}

Upvotes: 1

Related Questions