How to find the address of CCB Group Profiles

In a recent email request, a fellow reader asked me how to go about finding and displaying the address of a CCB Group.

So, to round out the month, we’ll focus on using the CCB API to display the address, latitude, and longitude for CCB groups. There’s not much that will change in this tutorial other than the CCB service name and xpath reference.

I’m not going into great detail as the code is the code, so let’s get this party started.Use the CCB API service group_profiles to retrieve (GET) and display the address, latitude, and longitude for CCB groups.  In the example below, be sure to change the the xpath reference to be //groups/group.

Next, you’ll need to set or define the following variables: $groupId, $latArr, $longArr and $response_object.

Then just like in previous tutorials, iterate each element of the XML, or transform the XML to JSON and access the object.  In this example, I’ll keep to the old form and iterate the XML object for each group_profile element.

Next, concatenate each of the following element variables and their respective values to themselves, and then echo each variable: $groupId, $latArr, $longArr and $response_object.

You don’t have to concatenate the variable values as I did.  And you’re done retrieving data.  Now go and study up on how to display the data with some CSS and Javascript.  Make it look pretty now. 😉

It’s just that easy to use the CCB API to retrieve and display group profiles and their respective values (i.e, address, latitude, longitude, etc.).  That’s all for this tutorial.  Stay tuned…


 * group profiles

// contains resusable globals and functions

$apiService = 'group_profiles'; // CCB api service

$urlData = array_filter( array(
	'srv' => "$apiService"
	) );

$rss = ccbDetails('get',$urlData); // transform to XML

$nodes = $rss->xpath('//groups/group');  // xpath for groups

$groupId = $latArr = $longArr = $response_object = '';

foreach ($nodes as $node)
    if(!empty($node->addresses->address->latitude) && !empty($node->addresses->address->longitude)){
    	$groupId .= $node['id'].",";
    	$latArr .= $node->addresses->address->latitude.",";
    	$longArr .= $node->addresses->address->longitude.",";
    	$response_object .= '[\''.$node->name.'\', '.$node->addresses->address->latitude.', '.$node->addresses->address->longitude.', \''.$node->image.'\', \''.addslashes($node->addresses->address->line_1).'\', \''.addslashes($node->addresses->address->line_2).'\'],';


$groupId = array(substr($groupId, 0, -1)); 
$latArr = array(substr($latArr, 0, -1));
$longArr = array(substr($longArr, 0, -1));

$response_object = array(substr($response_object, 0, -1));

echo 'Group IDs: '.$groupId.'<br/><br/>';
echo 'Group Latitudes: '.$latArr.'<br/><br/>';
echo 'Group Longitudes: '.$longArr.'<br/><br/>';
echo 'Group Address Arrays: '.$response_object.'<br/><br/>';





Related Posts

Subscribe and receive the following...

  • Inside CCB tips and tricks
  • Instant CCB tutorial alerts and updates
  • CCB How To's, Videos, Webinars and more...