Skip to content

Instantly share code, notes, and snippets.

@kellymears
Last active December 12, 2015 12:29
Show Gist options
  • Save kellymears/4772171 to your computer and use it in GitHub Desktop.
Save kellymears/4772171 to your computer and use it in GitHub Desktop.
/* get_group_members($group_id)
* ---------------------------------------------
* return multidimensional array of constituents
* in a particular group including address, contact
* information.
*
*/
function get_group_members($group_id) {
$this->convio_data['group_id'] = $group_id;
$responses = $this->convio_api->call('SRConsAPI_getGroupMembers', $this->convio_data);
foreach($responses as $response) {
$i = 0;
foreach($response->member as $member) {
$constituent[$i]['id'] = $member->cons_id;
$constituent[$i]['street1'] = $member->primary_address->street1;
$constituent[$i]['street2'] = $member->primary_address->street2;
$constituent[$i]['state'] = $member->primary_address->state;
$constituent[$i]['city'] = $member->primary_address->city;
$constituent[$i]['county'] = $member->districts->home_county;
$constituent[$i]['email'] = $member->email->primary_address;
$constituent[$i]['first_name'] = $member->name->first;
$constituent[$i]['last_name'] = $member->name->last;
// $constituent[$i]['coordinates'] = $this->get_geo_coordinates($member->primary_address->street1, $member->primary_address->city, $member->primary_address->state);
$i++;
}
}
return $constituent;
}
/* get_geo_coordinates($street, $city, $state)
* ---------------------------------------------
* return latitude and longitude from google
*
*/
function get_geo_coordinates($street, $city, $state) {
if(isset($street)) $address = $street + ' ';
if(isset($city)) $address .= $city + ' ';
if(isset($state)) $address .= $state;
$bad = array(
" " => "+",
"," => "",
"?" => "",
"&" => "",
"=" => ""
);
$address = str_replace(array_keys($bad), array_values($bad), $address);
$data = new SimpleXMLElement(file_get_contents("http://maps.google.com/maps/geo?output=xml&q={$address}"));
$coordinates = explode(",", $data->Response->Placemark->Point->coordinates);
return array(
"latitude" => $coordinates[0],
"longitude" => $coordinates[1]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment