Visual Studio 2010 と vb.net を使用して .asmx Web サービスを作成し、SQL Server 2008 を使用していますが、以下のクエリはデータベース内のすべてのアドレスを提供します。必要なのは、以下のクエリを、最も近い 10 か所の場所を返す空間クエリに変更することです。緯度と経度は小数ですが、データベースには [場所] という地理列があります。ヘルプ!
<WebMethod()> _
Public Function GetFuelStops(ByVal Lat as Double, ByVal Long as Double) As FuelStop()
Dim resultList = New List(Of FuelStop)()
Using sqlCon As New SqlConnection()
sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=Example_DB;User ID=Turd;Password=Fergison"
Dim sql = <sql>
SELECT
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [Lat]
, [Long]
, [Phone_Number]
FROM Gas_Stations
WHERE Location_Type = 1
</sql>
Dim command As New SqlCommand()
command.CommandText = CStr(sql)
command.Connection = sqlCon
sqlCon.Open()
Using reader = command.ExecuteReader()
While reader.Read()
Dim fuelStop = New FuelStop()
fuelStop.Physical_Address_Street = reader.GetString(0)
fuelStop.Physical_Address_Local = reader.GetString(1)
fuelStop.Physical_Address_State = reader.GetString(2)
fuelStop.Physical_Address_Zip = reader.GetString(3)
fuelStop.Phone_Number = reader.GetString(4)
resultList.Add(fuelStop)
End While
End Using
End Using
Return resultList.Skip(skip).Take(take).ToArray()
End Function