Added parsing support for lat/lng coords from device location

This commit is contained in:
laf
2015-11-16 18:50:52 -08:00
parent a6f34fdf7e
commit 7d7479b977
5 changed files with 30 additions and 6 deletions

View File

@@ -795,3 +795,15 @@ function ceph_rrd($gtype) {
$rrd = join('-', array('app', 'ceph', $vars['id'], $gtype, $var)).'.rrd';
return join('/', array($config['rrd_dir'], $device['hostname'], $rrd));
}
/**
* Parse location field for coordinates
* @param string location The location field to look for coords in.
* @return array Containing the lat and lng coords
**/
function parse_location($location) {
preg_match('/(\[)([0-9\. ]+), ([0-9\. ]+)(\])/', $location, $tmp_loc);
if (!empty($tmp_loc[2]) && !empty($tmp_loc[3])) {
return array('lat' => $tmp_loc[2], 'lng' => $tmp_loc[3]);
}
}//end parse_location()

View File

@@ -445,7 +445,10 @@ function location_to_latlng($device) {
if (!empty($device_location)) {
$new_device_location = preg_replace("/ /","+",$device_location);
// We have a location string for the device.
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location));
$loc = parse_location($device_location);
if (!is_array($loc)) {
$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device_location));
}
if (is_array($loc) === false) {
// Grab data from which ever Geocode service we use.
switch ($config['geoloc']['engine']) {