getLocation Method

Gets the user's X and Y coordinates as provided by Cisco Spaces.

This information is returned via the lambda expression locationHandler, which must be passed as parameter to getLocation method. The method will execute locationHandler providing a pair of double values, the first value is X position and the second value is Y position.

Particularly, in the iOS case, if an error occurs during getLocation method execution, this information is returned via a parameter in locationHandler handler.

iOS (Swift)

void OpenRoaming.getLocation(locationHandler: { location, error in <code> })

Android (Kotlin)

void OpenRoaming.getLocation { location -> <code> }

Method Parameters

Attribute Type Description Platform
locationHandler Lambda Expression Lambda expression to be executed at the end of the method Android iOS

Lambda parameters for locationHandler

Attribute Description Platform
location Pair of double values with the X, Y position of the user; first value is the X position, second value is Y position. iOS
Android
error OpenRoamingError (ENUM) with the error message if the method execution is not successful. If the method executes successfully, this parameter receives nil value. iOS

Code example

iOS (Swift)

OpenRoaming.getLocation(locationHandler: { location, error in
  if(error != null) {
    print(error!!)
  }else{
    print("X: "+String(location.first))
    print("Y: "+String(location.second))
  }
})

Dependencies

  • Import OpenRoaming_framework.
  • registerSdk method must have been called at some earlier time.
  • A user identity must have been already associated via associateUser method.

Possible exceptions

  • Swift does not throw any exception, but provides error messages on lambda expressions instead. For more information on existing error messages, see OpenRoamingError.

Android (Kotlin)

OpenRoaming.getLocation { location ->
  System.out.println("X: "+location.first)
  System.out.println("Y: "+location.second)
}

Dependencies

  • Import com.cisco.or.sdk.OpenRoaming.
  • registerSdk method must have been called at some earlier time.
  • A user identity must have been already associated via associateUser method.
  • Allowed permissions: "android.permission.INTERNET".

Possible exceptions

  • NotInitializedException
  • NotSignedException
  • ServiceBadResponseException

For more information on possible exceptions, see Exceptions.