OnLocationChanged 给我 11 分,每次我有 11 次调用 php 页面。如何确保我每次只发送最后 11 个(可能不是 11 个)位置点。这可能是第一次插入的好方法数据进入 sqlite 数据库,然后调用一个计时器来获取 sqlite 表的最后一行并将其传递给 php 页面,稍后它将删除该表并在 2 分钟内重复所有操作。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText ed1=(EditText) findViewById(R.id.editText1);
final EditText ed2=(EditText) findViewById(R.id.editText2);
final EditText ed3=(EditText) findViewById(R.id.editText3);
final WebView w=(WebView) findViewById(R.id.webView1);
final Time t=new Time();
//deo koji naknadno ubacujem za kriterijum
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
//kraj dela koji sam naknadno ubacio
final LocationManager m=(LocationManager) MainActivity.this.getSystemService(Context.LOCATION_SERVICE);
//deo koji sam takodje ubacio naknadno
String locationprovider =m.getBestProvider(criteria,true);
//deo koji sam takodje ubacio naknadno kraj
LocationListener l=new LocationListener() {
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location arg0) {
/*
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
String date = dateFormat.format(new Date());
*/
//novi datum
/*
Date datum = new Date();
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("MM/dd/yyyy");
String date=sdf.format(datum);
//novi datum
*/
/*
//treci datum
String pattern = "MM/dd/yyyy";
SimpleDateFormat format = new SimpleDateFormat(pattern);
String date= format.format(new Date());
//treci datum
*/
//cetvrti datum
String format="MM/dd/yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(format,Locale.US);
String date= sdf.format(new Date());
//cetvrti datum
String url=new String();
t.setToNow();
ed1.setText("");
ed2.setText("");
String longitude=new String();
String latitude=new String();
String speed=new String();
if((int)arg0.getSpeed()==0)
{
speed="0";
}
else
{
speed=""+(((int)arg0.getSpeed()*3600)/1000);
}
longitude=""+ arg0.getLongitude();
latitude=""+ arg0.getLatitude();
ed1.setText(longitude);
ed2.setText(latitude);
ed3.setText(speed);
Calendar cal=Calendar.getInstance();
url="http://www.compensatemeonline.com/truckmeonline/TruckMeOnline/UnosLokacijaSaTelefona.php?id=16"+"&longitude="+longitude+"&latitude="+latitude+"&brzina="+speed+"&vreme="+cal.getTime()+"&datum="+date;
try{
w.loadUrl(url);
}
catch (Exception e) {
// TODO: handle exception
}
// TODO Auto-generated method stub
}
};
// TODO Auto-generated method stub
m.requestLocationUpdates(locationprovider, 120000, 0, l);
// zamenio sam m.requestLocationUpdates(LocationManager.GPS_PROVIDER, 120000, 0, l); sa m.requestLocationUpdates(locationprovider, 120000, 0, l);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}