验证纬度和经度 [英] Validate latitude and longitude

查看:126
本文介绍了验证纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证纬度和经度。现在,我只是检查值是否不为空,但我想通过验证来确认它是有效的纬度或经度。

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.

我该怎么做?

我的财产看起来像这样:

My property looks like this:

public string Lat
{
    get {
        return this._lat; 
    }
    set 
    {
        base.ValidationErrors.Remove("Lat");

        if (String.IsNullOrWhiteSpace(value))
        {
            this.ValidationErrors.Add("Lat", strings.Positions_Lat_Empty);
        }

        this._lat = value != null ? value.Trim() : null;
    }
}

public string Lng
{
    get { 
        return this._lng; 
    }
    set {

        base.ValidationErrors.Remove("Lng");

        if (String.IsNullOrWhiteSpace(value))
        {
            this.ValidationErrors.Add("Lng", strings.Positions_Lng_Empty);
        }

        this._lng = value != null ? value.Trim() : null; 
    }
}


推荐答案

从MSDN

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


纬度测量北或$ b的距离在赤道以南的$ b位置是
。赤道位于
0°,北极位于北纬90°(或
90°,因为正纬度
意味着北),而南极位于
90向南(或–90°)。纬度
的测量范围是0°到
(+/–)90°。

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

经度测量的是东边或西边的
位于本子午线的位置是
。本初子午线在英国格林威治市运行
。经度
的测量范围是0°到
(+/–)180°。

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

在设置者的纬度中,检查是否设置的值介于-90到90度之间。如果不是,则抛出异常。对于您的经度,请检查该值是否介于-180到180度之间。如果不是,则抛出异常。

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.

这篇关于验证纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆