2017-12-27 8 views
1

그래서 안드로이드 points = new ArrayList<LatLng>();을 사용하여 사용자의 GPS 위치를 매 3 초마다 추적합니다. 길이가 길면 경로가 최대 1,000 또는 그 이상일 수 있습니다. 그들이 PHP로 마무리하고 mysql에 저장 한 후에이 경로를 보내는 가장 좋은 방법은 무엇입니까? 나는 현재 데이터베이스에 연결하기 위해 발리 슛을 사용하고 있지만 너무 많은 정보를 루프에 보내려고하면 시간이 초과 된 것처럼 보입니다. 각 위치마다 개별적으로 IE가 있습니다.안드로이드가 PHP로 길게 보내고 MySQL에 저장

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); 
+0

시도를 보내 ... 앱은 중포 기지 데이터베이스를 업데이트해야 빠를 것이다 지리적 위치 좌표, mysql에 저장할 서비스를 호출하면 –

+0

사용자가 끝날 때 모든 지점을 보내려고하면 –

+0

json으로 모든 위치 데이터를 보낼 수 있습니다. 훨씬 더 효율적 일 것입니다. – himel

답변

0

내가 수와 모든 시간을 공유 우선 onLocationChanged()에 저장하고 난 증가하고있다 : 여기

mLastLocation = location; 
LatLng latLng = new LatLng(latitude, longitude); 
points.add(latlng); 

내 발리 요청입니다 : 여기

내가 내 LatLng를 얻을 방법입니다 카운트.

그러면 공유 환경 설정에서 latlong을 수집하는 한 가지 방법을 만들었고 json 배열을 만들고 있습니다. POST 메서드로 데이터 보내기 GET 메서드를 사용하여 대량의 json 데이터를 보내지 마십시오.

@Override 
public void onLocationChanged(Location location) { 


      editdata.putString("latitude" + data_count, 
         "" + location.getLatitude()); 

       editdata.putString("longitude" + data_count, 
         "" + location.getLongitude()); 

       editdata.putString("bearing" + data_count, 
         "" + location.getBearing()); 
       editdata.putInt("count", data_count); 
       data_count++; 
       editdata.commit(); 

} 

//collect data from preference like 
    ArrayList<HashMap<String, String>> arr_list = new ArrayList<HashMap<String, String>>(); 

JsonArray strJson ; 

    public void parse(){ 
     arr_list .clear(); 

     for (int i = first; i < tripdata.getInt("count", 0); i++) { 
      HashMap<String, String> map = new HashMap<String, String>(); 
      map.put("lat", "" + latitude); 
      map.put("long", "" + longitude); 
      map.put("bearing", bearing); 

      arr_list.add(map); 

} 


     if (arr_list.size() > 0) { 
      strJson = new JSONArray(arr_list).toString(); 
      strJson = "{\"latlng\":" + strJson + "}"; 
     } 
    } 

    //here strJson is yout JSONArray Latlong data list 
0

이 사이트를 참조 할 수 있습니다. 이 안드로이드 폰의 위치를 ​​추적하기 위해 나에게 정말 도움이되었다 및 중포 기지 데이터베이스를 사용하여 PHP를 통해 MySQL로

https://www.websmithing.com/gps-tracker/

관련 문제