【发布时间】:2018-06-07 18:23:18
【问题描述】:
所以我使用 Android points = new ArrayList<LatLng>(); 每 3 秒跟踪一次用户的 GPS 位置,如果他们在足够长的路线上,有时可以达到 1,000 或更多点。在他们完成到我的 php 并将其存储到 mysql 后发送此路由的最佳方法是什么?我目前正在使用 volley 连接到我的数据库,但是如果我尝试在循环中发送太多信息(即每个位置单独发送太多信息)似乎会超时。
这是我获取 LatLng 的方法:
mLastLocation = location;
LatLng latLng = new LatLng(latitude, longitude);
points.add(latlng);
这是我的截击请求:
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_FOR_GPS,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("GPS save route", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
//adding parameters to the request
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("command", "saveGPSroute");
params.put("userId", userId);
return params;
}
};
// Add the request to the RequestQueue.
queue.add(stringRequest);
【问题讨论】:
-
尝试使用firebase数据库...应用程序应该更新firebase数据库的地理位置坐标,这将比调用存储在mysql中的服务更快
-
您也可以尝试在用户完成旅行后发送所有积分
-
您可以将所有位置数据发送为 json ,我想这样会更有效率
-
@HarshPatel 我试过了,如果我在循环中单独发送它们,截击超时。我不太了解 JSON 对象,但我也在研究一种方法,但不确定 volley 是否会超时。
-
尝试发送 json 数组而不是一次发送单个项目
标签: php android mysql location android-volley