update geopoint using objectid

If we add a geopoint in onLocationChanged method; many geopoints will be created in geocategory. In Parse geopoint get created just in Data table not as a relation.
what is the best way in backendless to update a gepoint which is a data object field ?
My solution is this:
1- create a geopoint and store its objectid after being created locally or in separate data object for every user
2- create a geoquery and find a geopoint using the stored objectid then set the Lat Lng and save the geopoint again
but the above solution adds too much code for the job that easily get done in Parse simply writing one line of code:

 ParseGeoPoint userLocation = new ParseGeoPoint(location.getLatitude(),
location.getLongitude());

Could we solve the problem using Bussiness logic to automate the geopoint update process?

Hi!

As a solution you can add server side custom logic in API Engine:
https://backendless.com/documentation/api-engine/apieng_overview.htm
On server side you can add method which will accept objectId of existing data object and new Latitude, Longitude. In service method you can implement all logic of finding and updating.
Regards,
Kate.

Hi
would you provide a sample code for geopoint update ? there isn’t any in the documentation.
Regards
Mousa

You can use this documentation: https://backendless.com/documentation/geo/android/geo_adding_a_geo_point.htm
Geo update API relies on the same methods used for Adding a Geo Point. The primary difference is in order to update a geo point it must have the objectId property assigned by Backendless.

Hi

this is my code to query geopoints in a rider category and comparing every geopoint objectid with the objectid which I get after initial geopoint being added to category.
as you see how much code get complicated. Is there a easier way to update existing geopoint?

BackendlessDataQuery dataQuery = new BackendlessDataQuery(); 
String currentUsername = String.valueOf(Backendless.UserService.CurrentUser().getProperty("username")); 
dataQuery.setWhereClause("requesterUserName =" + "'" + currentUsername + "'"); 
Backendless.Data.of(Requests.class).find(dataQuery, new AsyncCallback<BackendlessCollection<Requests>>() { 
 @Override 
 public void handleResponse(BackendlessCollection<Requests> response) { 
 List<Requests> requestsList = response.getCurrentPage(); 
 for (final Requests request : requestsList) { 
 BackendlessGeoQuery geoQuery = new BackendlessGeoQuery(); 
 geoQuery.addCategory("rider"); 
 Backendless.Geo.getPoints(geoQuery, new AsyncCallback<BackendlessCollection<GeoPoint>>() { 
 @Override 
 public void handleResponse(BackendlessCollection<GeoPoint> response) { 
 List<GeoPoint> geoPoints = response.getCurrentPage(); 
 for (GeoPoint geoPoint : geoPoints) { 
 if (geoPoint.getObjectId().equals(objectId)) { 
 geoPoint.setLatitude(myLocation.latitude); 
 geoPoint.setLongitude(myLocation.longitude); 
 Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() { 
 @Override 
 public void handleResponse(GeoPoint response) { 
 request.setRequesterLocation(response); 
 
 Backendless.Persistence.save(request, new AsyncCallback<Requests>() { 
 @Override 
 public void handleResponse(Requests response) { 
 Log.i("AppInfo", "Longitude after save: " + response.getRequesterLocation().getLongitude().toString()); 
 } 
 
 @Override 
 public void handleFault(BackendlessFault fault) { 
 
 } 
 }); 
 } 
 
 @Override 
 public void handleFault(BackendlessFault fault) { 
 
 } 
 }); 
 
 
 } 
 } 
 }


To update a geopoint you need to know geopoint’s objectId OR have the geopoint object loaded from the server.

If I know the geopoint A’s objectid and create a geopoint B then set the objectid of point B same as point A Backendless creates two points A and B on the category not assigning B to A .

GeoPoint A = new GeoPoing(10.0,10,0);

A.addCategory("rider");
String pointAObjectId = A.getObjectId();
GeoPoint B = new GeoPoint(10.2,10.2);
B.setObjectId(pointAObjectId);
Backendless.Geo.save(B);

please provide a sample code

GeoPoint A = new GeoPoing(10.0,10,0);
A.addCategory("rider");
String pointAObjectId = A.getObjectId();
GeoPoint B = new GeoPoint(10.2,10.2);
B.setObjectId(pointAObjectId);
Backendless.Geo.save(B);


Try assigning the same category too.

Thanks for the help this is my code working properly:

SharedPreferences pref = getSharedPreferences("GeoPoint_ObjectId",Context.MODE_PRIVATE);
objectId = pref.getString("objectId",null);
GeoPoint riderLocation = new GeoPoint(location.getLatitude(),location.getLongitude());
if(objectId != null){
    riderLocation.setObjectId(objectId);
}
riderLocation.addCategory("rider");
Backendless.Geo.savePoint(riderLocation, new AsyncCallback<GeoPoint>() {
    @Override
    public void handleResponse(GeoPoint response) {
        if (objectId == null) {
            SharedPreferences preferences = getSharedPreferences("GeoPoint_ObjectId", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString("objectId", response.getObjectId());
            editor.commit();
        }
    }

    @Override
    public void handleFault(BackendlessFault fault) {

    }
});

If I understood you correctly, the problem has been resolved. I will mark this topic as Solved.