现在我正在开发一个应用程序来绘制地图上的坐标作为标记,所有坐标都存储在数据库中并完成,现在我想用按钮和listview控件创建另一个活动,用户在点击按钮时从当前位置获取最近的坐标在列表视图中。我使用android位置服务获取当前位置纬度和经度,并使json api从数据库获取我的坐标。现在的问题是如何过滤坐标,从当前位置获取最接近的坐标并显示在列表视图中。
public void getJSONString()
{
var request = HttpWebRequest.Create(string.Format(@"http://citysoftech.net/Coordinates/locations.php"));
request.ContentType = "application/json";
request.Method = "GET";
var content = "";
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
content = reader.ReadToEnd();
if (string.IsNullOrWhiteSpace(content))
{
Console.Out.WriteLine("Response contained empty body...");
}
else
{
Console.Out.WriteLine("Response Body: \r\n {0}", content);
}
Assert.NotNull(content);
}
}
Toast.MakeText(this, content, ToastLength.Short).Show();
initializeMap(content); //calling map
}
/**
*
try
{
JSONArray json = new JSONArray(content);
for (int i = 0; i < json.Length(); i++)
{
JSONObject obj = json.GetJSONObject(i);
String lati = obj.GetString("latitude");
String longi = obj.GetString("longitude");
Double.Parse(longi)))
}
catch (JSONException e)
{
e.StackTrace.ToString();
}