SELECT * , 3956 *2 * ASIN( SQRT( POWER( SIN( ( 122.4058 - ABS( dest.lat ) ) * PI( ) /180 /2 ) , 2 ) + COS( 122.4058 * PI( ) /180 ) * COS( ABS( dest.lat ) * PI( ) /180 ) * POWER( SIN( ( 37.7907 - dest.lon ) * PI( ) /180 /2 ) , 2 ) ) ) AS distance
FROM members dest
HAVING distance <25

Above query run perfectly .. Users will have one field name search_distance .. So i want to calculate users location and current location distance based in search_distance too..

Please help me to solve this ! Let me know if this is not clear


User Table have below fields
id, user_name, lat, lon, search_distance

Hi, found this on the web and tested it.

<script type="text/javascript">
<!--


function formatOutput(num)
{
	if (num > 10) 
		return parseInt(num);
	return num;
}

function validate(num, name)
{
	if (isNaN(num))
	{
		alert("Invalid input for " + name);
		return 1;
	}
	return 0;
}

function distance()
{
	var lat_1 = parseFloat(document.getElementById("lat1").value);
	var lat_2 = parseFloat(document.getElementById("lat2").value);
	var lon_1 = parseFloat(document.getElementById("lon1").value);
	var lon_2 = parseFloat(document.getElementById("lon2").value);
	
	
	var errorCount = 0;
	errorCount += validate(lat_1, "the first latitude");
	errorCount += validate(lat_2, "the second latitude");
	errorCount += validate(lon_1, "the first longitude");
	errorCount += validate(lon_2, "the second longitude");
	if (errorCount > 0)
		return;

	var rho = 3960.0; // earth diameter in miles
	var phi_1 = (90.0 - lat_1)*Math.PI/180.0;
	var phi_2 = (90.0 - lat_2)*Math.PI/180.0;
	var theta_1 = lon_1*Math.PI/180.0;
	var theta_2 = lon_2*Math.PI/180.0;
	
	var d = rho*Math.acos( Math.sin(phi_1)*Math.sin(phi_2)*Math.cos(theta_1 - theta_2) + Math.cos(phi_1)*Math.cos(phi_2) );
	
	var output = "Distance = " + formatOutput(d) + " miles or " + formatOutput(1.609344*d) + " kilometers";
	
	document.getElementById("result").firstChild.nodeValue = output;
}

// -->
</script>
<form method="post" action="">
	<p>Fill in the latitude and longitude of two geographic locations and 
	compute the distance between the points.</p>
	<table border="0">
		<tr>
			<td> </td>
			<td>Latitude &deg;North </td>
			<td>Longitude &deg;East </td>
		</tr>
		<tr>
			<td>First location: </td>
			<td><input type="text" id = "lat1" name="lat1" size="20" tabindex="1" /></td>
			<td><input type="text" id = "lon1" name="lon1" size="20" tabindex="2" /></td>
		</tr>
		<tr>
			<td>Second location: </td>
			<td><input type="text" id = "lat2" name="lat2" size="20" tabindex="3" /></td>
			<td><input type="text" id = "lon2" name="lon2" size="20" tabindex="4" /></td>
		</tr>
	</table>
	<p id="result">Distance ...</p>
	<p><input type="button" value="Calculate" name="B1" tabindex="5" onclick = "distance()" /></p>
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.