我已经四处搜索了,我看到你可以使用myGeography.Lat
访问纬度,但在尝试阅读sqldatareader
时它似乎不起作用,这就是我正在尝试:
String sql = "SELECT * FROM myTable WHERE myGeography.STDistance(geography::Point(somelatitude, somelongitude, 4326)) <somerange
SqlDataReader reader = command.ExecuteReader()
int lat,long
lat = reader["myGeography.Lat"]
long = reader["myGeography.Long"]
答案 0 :(得分:1)
SQL Geography是一种转换为Microsoft.SqlServer.Types.SqlGeography的数据类型。假设myGeography是一个地理位置,你可以这样做:
Microsoft.SqlServer.Types.SqlGeography geo = (Microsoft.SqlServer.Types.SqlGeography)reader.GetValue["myGeography"];
int long = geo.Long;
int lat = geo.Lat;