Backendless Support
 

Saving a data object with a related geolocation

This is a Backendlessbrand new feature from the release 1.9.0. and it is a very powerful one- the potential of mapping a location to a data object can lead to a lot of interesting opportunities. 

For example, consider a taxi booking service like Uber. A developer may have multiple cars/drivers available for hire as well as customers putting pickup requests. Both drivers and customers may be represented by corresponding data objects and locations on the map. 

Consider the following example.

Synchronous API sample (Plain Java only):

private static void saveDataWithGeoSync()
{
 Driver driver = new Driver();
 driver.setDriverName( "Ruben Barrichelli" );
 driver.setRating( 5 );
 driver.setCarMake( "Mercedes" );
 driver.setCarModel( "E350" );
 GeoPoint location = new GeoPoint( 41.878247, -87.629767 );
 location.addMetadata( "city", "Chicago" );
 location.addCategory( "drivers" );
 driver.setLocation( location );
 Backendless.Data.of( Driver.class ).save( driver );
}
Asynchronous API sample (Plain Java and Android):
private static void saveDataWithGeoAsync()
{
 Driver driver = new Driver();
 driver.setDriverName( "Jen Buttons" );
 driver.setRating( 4 );
 driver.setCarMake( "Lamborghini" );
 driver.setCarModel( "Diablo" );
 GeoPoint location = new GeoPoint( 32.803468, -96.769879 );
 location.addMetadata( "city", "Dallas" );
 location.addCategory( "drivers" );
 driver.setLocation( location );
 Backendless.Data.of( Driver.class ).save( driver, new AsyncCallback<Driver>()
 {
 @Override
 public void handleResponse( Driver driver )
 {
 System.out.println( "Driver has been saved. Location object ID " + driver.getLocation().getObjectId() );
 }
 @Override
 public void handleFault( BackendlessFault fault )
 {
 }
 } );
}

If a developer runs both functions and navigate to Backendless console, he/she will see the following in the Data screen: 

NOTICE: the "location" property/column contains a hyperlink with the coordinates of the geopoint linked to the data object. If a developer clicks the link for the first data object (Jen Buttons driving the Diablo), the following appears on the screen: 

The console shows the geopoint linked to the data object. The geopoint is displayed with its metadata (see the table) and the plotting on the map. This makes it very convenient for diagnosing data relations and instrumenting a developer's backend storage.

Is article helpful?