我目前有一个webservice,它是我在visual Studio2010中用Visual basic构建的asmx webservice。目前,当我用我的android应用程序查询get服务时,我从数据库中获得了指定数量的地址。我需要的是Android应用程序将用户的当前位置传递给but服务,并让它返回数据库中最近的10个地址列表,但我该如何做到这一点呢?
下面是我查询数据库的方法。
<WebMethod()> _
Public Function GetFuelStops(ByVal skip As Integer, ByVal take As Integer) As FuelStop()
Dim resultList = New List(Of FuelStop)()
Using sqlCon As New SqlConnection()
sqlCon.ConnectionString = "Data Source=(local);Initial Catalog=****;User ID=****;Password=***(***"
Dim sql = <sql>
SELECT
[Physical_Address_Street]
, [Physical_Address_Local]
, [Physical_Address_State]
, [Physical_Address_Zip]
, [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()发布于 2013-04-24 10:07:21
您的应用程序需要启用GPS (这将触发当前位置坐标),即纬度和经度。
同时,您的数据库表应该具有每个地址的纬度和经度值,因为这些纬度和经度值将用于距离比较。
一旦有了所有的纬度/经度值,就需要在查询中使用sin/cos公式从数据库中返回前5条或前10条记录。
干杯
https://stackoverflow.com/questions/16181158
复制相似问题