30 lines
1.6 KiB
PHP
30 lines
1.6 KiB
PHP
<?php
|
|
//map container
|
|
echo '<div id="googleMapContainer" style="width:750px;height:570px;"></div>';
|
|
//load Script
|
|
echo '<script type="text/javascript" src="modules/Accounts/javascript/showMap.js"></script>';
|
|
echo '<script src="https://maps.googleapis.com/maps/api/js"></script>';
|
|
$ids = explode(",",$_REQUEST['uid']);
|
|
//get Data
|
|
$markers = array();
|
|
foreach ($ids as $id) {
|
|
$a = new Account();
|
|
$a->retrieve($id);
|
|
$addr = $a->billing_address_street." ".$a->billing_address_postalcode." ".$a->billing_address_city." ".$a->billing_address_country;
|
|
$cor = getCoordinates($addr);
|
|
$tmp = array();
|
|
$tmp['lat'] = $cor[0];
|
|
$tmp['lng'] = $cor[1];
|
|
$tmp['title'] = html_entity_decode(trim($a->name));
|
|
$tmp['info'] = '<a href="index.php?module=Accounts&action=DetailView&record='.$a->id.'" target="new">'.html_entity_decode(trim($a->name)).'</a><br>'.$a->billing_address_street.'<br>'.$a->billing_address_postalcode.'<br>'.$a->billing_address_city.'<br>'.$a->billing_address_country;
|
|
$markers[] = $tmp;
|
|
}
|
|
echo '<input value="'.base64_encode(json_encode($markers)).'" id="googleMapMarkers" type="hidden"></input>';
|
|
function getCoordinates($address){
|
|
$address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern
|
|
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";
|
|
$response = file_get_contents($url);
|
|
$json = json_decode($response,TRUE); //generate array object from the response from the web
|
|
return array ($json['results'][0]['geometry']['location']['lat'],$json['results'][0]['geometry']['location']['lng']);
|
|
}
|
|
?>
|