这里林新手..香港专业教育学院想知道,如果我的情况是可能的,因为我没有对如何做到这一点的参考....
在我的数据库帮助:
public boolean saveLocationToLocalDatabase(String serialNumber, String
latitude, String longitude, String dateTime, String speed, String
port, SQLiteDatabase db)
{
ContentValues contentValues = new ContentValues();
contentValues.put(SERIALNUMBER, serialNumber);
contentValues.put(LATITUDE, latitude);
contentValues.put(LONGITUDE, longitude);
contentValues.put(DATE_TIME, dateTime);
contentValues.put(SPEED, speed);
contentValues.put(PORT, port);
long locationResult=db.insert(TABLE_FLEET_LOCATION, null,
contentValues);
if (locationResult == -1)
return false;
else
return true;
}
这是我的onclicklistener并让我的数据是取我的SQLite数据库。
locate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick( View view) {
mMap.setOnMyLocationChangeListener(new
GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
CameraUpdate center = CameraUpdateFactory.newLatLng(new
LatLng(location.getLatitude(), location.getLongitude()));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);
mMap.clear();
MarkerOptions mp = new MarkerOptions();
mp.position(new LatLng(location.getLatitude(),
location.getLongitude()));
mp.title("");
mMap.addMarker(mp);
mMap.moveCamera(center);
mMap.animateCamera(zoom);
String gg =Settings.Secure.getString(getApplicationContext()
.getContentResolver(),Settings.Secure.ANDROID_ID);
lat = Double.toString(location.getLatitude());
lon = Double.toString(location.getLongitude());
well = String.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
java.util.Locale.getDefault()).format(new java.util.Date()));
speed="0000";
port="9090";
}
这是我的数据保存到我的数据库:
DatabaseHelper databaseHelper = new
DatabaseHelper(getApplicationContext());
SQLiteDatabase db = databaseHelper.getWritableDatabase();
boolean accepted = databaseHelper.saveLocationToLocalDatabase(gg,lat,
lon, well,speed,port, db);
if (accepted == true)
Log.w("Data Entered:","MAIN");
}
如果我找到我的数据:这是我的SQLite数据库我的样本场:注意:如果你发现我一直保存数据变化前5点的数据,因为由于数据我想检索另一数据之前将其保存每一秒。
而这是我的情况下,是有可能做到这一点?“伊夫喜欢让所有的数据,并通过JSON对象建造这一切,并通过改造发送到API”
顺便说一下,我最后的代码是只获得了一次数据IVE从我的onclick监听器获取,但香港专业教育学院喜欢做的另一种方式(通过保存的数据,如5-10 DATAS而这一切都通过改造发送到API)为我的错误捕获的目的。
以前改装代码:私人无效sendAllToApi(){
MapDetails mapDetails = new MapDetails(gg, lat, lon,
well, "0", portInts); //Data ive get once ive pressed
onclicklistener
List<MapDetails> data = new ArrayList<>();
data.add(mapDetails);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://" + ADDRESS + ":" + PORT)//this
is my configuration for api link
.addConverterFactory(GsonConverterFactory.create());
Retrofit retrofit = builder.build();
Api locate = retrofit.create(Api.class);
Call<MapDetails> call = locate.mapDetailLocation(data);
call.enqueue(new Callback<MapDetails>() {
@Override
public void onResponse(Call<MapDetails> call,
Response<MapDetails> response) {
Snackbar.make(view, "" + response,
Snackbar.LENGTH_INDEFINITE)
.setAction("Action", null).show();
}
@Override
public void onFailure(Call call, Throwable t) {
Snackbar.make(view, "" + t.getMessage(),
Snackbar.LENGTH_INDEFINITE)
.setAction("Action", null).show();
}
});
}