I have longitude and latitude stored in database like
table name: km_stores fields: store_id, store_long, store_lat, store_name
How can I pull the nearest stores using their longitude and latitude?
I am using
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
document.getElementById("km_long").value = position.coords.latitude;
document.getElementById("km_lat").value = position.coords.longitude;
}
</script>
<strong>Long:</strong> <input type="text" id="km_long" /> <strong>Latitude:</strong> <input type="text" id="km_lat" />
[php]
global $wpdb;
$results = $wpdb->get_results('select * from km_stores', OBJECT );
foreach ($results as $store) {
echo $store->store_name;
}
[/php]
[php][/php]
tags because I am using PHP in WordPress Pages Plugin.