Skip to content

Retrieving Geo Categories

This API retrieves a list of all the application's geo categories.

Blocking API

public List<GeoCategory> Backedless.Geo.getCategories() throws BackendlessException

Non-Blocking API

public void Backedless.Geo.addCategory( AsyncCallback<List<GeoCategory>> responder )

where:

Argument                Description
responder a responder object which receives a callback when the method successfully retrieves the categories contained in the application or if an error occurs. Applies to the asynchronous methods only.

Return Value

A list of the GeoCategory objects. Each GeoCategory instance represents a category with the properties of objectId, name and number of geo points in it.

package com.backendless.geo;

public class GeoCategory implements Comparable<GeoCategory>
{
  private String objectId;
  private String name;
  private int size;

  // returns objectId assigned to the category
  public String getId()
  {
    return objectId;
  }

  // returns category name
  public String getName()
  {
    return name;
  }

  // returns number of geo points in the category
  public int getSize()
  {
    return size;
  }

  public void setName( String name )
  {
    this.name = name;
  }

  @Override
  public boolean equals( Object o )
  {
    if( this == o )
      return true;

    if( o == null || getClass() != o.getClass() )
      return false;

    GeoCategory that = (GeoCategory) o;

    if( !name.equals( that.name ) )
      return false;

    if( objectId != null ? !objectId.equals( that.objectId ) : that.objectId != null )
      return false;

    return true;
  }

  @Override
  public int hashCode()
  {
    int result = objectId != null ? objectId.hashCode() : 0;
    result = 31 * result + name.hashCode();
    return result;
  }

  @Override
  public String toString()
  {
    final StringBuffer sb = new StringBuffer();
    sb.append( "GeoCategory" );
    sb.append( "{name='" ).append( name ).append( '\'' );
    sb.append( ", size=" ).append( size );
    sb.append( '}' );
    return sb.toString();
  }

  @Override
  public int compareTo( GeoCategory arg )
  {
    if( this == arg )
      return 0;

    int nameDiff = this.name == null ? 
                   (arg.getName() == null ? 0 : -1) : 
                   this.name.compareTo( arg.getName() );

    if( nameDiff != 0 )
      return nameDiff;

    return size - arg.getSize();
  }
}

Example

Backendless.Geo.getCategories(new AsyncCallback<List<GeoCategory>>()
{
  @Override
  public void handleResponse( List<GeoCategory> category )
  {
  }

  @Override
  public void handleFault( BackendlessFault backendlessFault )
  {

  }
}