Validate latitude and longitude

后端 未结 4 1340
鱼传尺愫
鱼传尺愫 2021-02-01 03:04

I want to validate the latitude and longitude. Right now, I check just so that the value is not empty, but I want a validation to check that it is a valid latidue or longitude.<

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 03:16

    From MSDN

    http://msdn.microsoft.com/en-us/library/aa578799.aspx

    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°.

    enter image description here

    In your setter for latitude, check if the value being set falls between -90 and 90 degrees. If it doesn't, throw an exception. For your longitude, check to see if the value falls between -180 and 180 degrees. If it doesn't, throw an exception.

提交回复
热议问题