I have a database with 3000~ locations stored as coordinates. I want to only pick out a certain amount of locations within a radius of x km.
Like this:
Currently I am generating a XML file with PHP to grab the entries from the database, there should be a way to only pick out the lat/lon that I need withing a certain radius of x lat/x lon. Here's the code:
<?php
require_once("db.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Select all the rows in the markers table
$query = "SELECT * FROM addresses";
$result = mysqli_query($conn, $query);
if (!$result) {
die('Invalid query: ' . mysqli_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo "<?xml version='1.0' ?>";
echo '<markers>';
$ind=0;
// Iterate through the rows, printing XML nodes for each
while ($row = @mysqli_fetch_assoc($result)){
// Add to XML document node
echo '<marker ';
echo 'id="' . $row['id'] . '" ';
echo 'name="' . $row['id'] . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="House" ';
echo '/>';
$ind = $ind + 1;
}
// End XML file
echo '</markers>';
?>