How to find distance between two places using longitude and latitude PDF Print E-mail
Written by Kuldip Pabla   
Saturday, 17 April 2010 21:12

Sometimes we need to find out list of places that are within a certain radius from a center place where coordinates of the places are saved in the database as latitude (lat float(10,6)) & longitude (lng float(10,6)).

There are two possible options:

1) Loop through all the places in the databases, find the distance from the center point and keep the places that have distance less or equal to the radius.

2) Define an sql function to find the distance between two places, and select the places having distance less or equal to the radius.

Obviously the second option is way better and efficient than the first one.  Here is how you do it

DROP FUNCTION IF EXISTS `getDistance`$$   // drop any previously defined function
CREATE FUNCTION `getDistance`(lat1 float(10,6),lng1 float(10,6), c1 VARCHAR(120), c2 VARCHAR(30)) 
DECLARE lng2, lat2, distance float(10,6); 
select CAST(c1 as DECIMAL(10,6)) into lat2; 
select CAST(c2 as DECIMAL(10,6)) into lng2; 
select ((ACOS(SIN(lat1 * PI() / 180) * SIN(lat2 * PI() / 180) + COS(lat1 * PI() / 180) * COS(lat2 * PI() / 180) * COS((lng1 - lng2) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) into distance; 
RETURN distance; 


It defines a MySQL function that you can use from within your code or using SQL query

USAGE: select id, email from custs where getDistance (lat, lng, x, y) <= radius;


lat: is a column in your database representing latitude of a place

lng: is a column in your database representing longitude of a place

x: is the latitude of a central position, say "36.288757"

y: is the longitude of a central position, say "111.804558"

radius: is the radius within which you want to find places.

Last Updated on Sunday, 18 April 2010 01:37
Selecting / Unselcting All Checkbox PDF Print E-mail
Java Script
Written by Kuldip Pabla   
Sunday, 10 January 2010 01:08

Often, we run into situations where we would love to have just one button to select all the options on a given page. For example, in Webmail, if I want to delete old emails or junk emails, it is easier to select them all and then click delete. However, it is pain if I have to select each and every email one by one. One check box that can select and unselect all them at once comes to help.

At KSPTech, we ran into a similar situation with a project. Following is the javascript code snippete that I would like to share with you on as is basis.


checked = false;

function toggleCheckbox (list) {

if (checked == false) {

checked = true;

} else {

checked = false;


for (i = 0; i < list.length; i++) {

list[i].checked = checked;





<form name="myform">

<input type="checkbox" name="list" >

<input type="checkbox" name="list" >

bunch of more check boxes to be toggled


<input type='checkbox'  onclick='toggleCheckbox(document.myform.list)'> Select / Unselect All

Google Search Engine in $250 PDF Print E-mail
Written by Kuldip Pabla   
Friday, 20 November 2009 04:36

Google Search Engine in $250! Yes, that is correct. no Millions and no Billions.

Is there someone who would develop a clone of Google Search Engine in $250? Yes, do not get surprised! While surfing around, I came across this requirement on oDesk that requires someone to develop a Google like Search Engine for $250.

Well, I'll be ready to pay 10 times or even more to get a Google Search Engine kind of functionality.

And that is not it, it needs to be delivered by sometime in January of 2010 guys. What th eheck Google was doing all these years in developing a search engine, when someone can do it in less than 3 months?


Is FaceBook Hacked? PDF Print E-mail
Written by Kuldip Pabla   
Monday, 04 January 2010 16:35

Happy New Year to all of you!

No, this is not a hack or a mass message spread by Facebook. These are my own wishes for you from the bottom of the heart. I wish you that you never get bombarded with spams and hacks.

On the very first day of this year, I got greeted by a message from Facebook:

"hey there I was just talking to Aditya and they asked me to show you this AmericanBizNews . org"

Soon, I knew it was some kind of virus or FB hack that is mas contacting FB members. However, I did not care much about it. I never knew anyone named Aditya in my whole life.

To my surprise, I had better greetings waiting in my INBOX this morning when I woke up. These were sort of "angered" messages from my own friends who had received a similar message. This time it was from me - I mean someone acting like me. You know what I mean.

As the FB is growing larger than image, it has been loosing control over everything. A few weeks ago, I had blogged about how CPU consuming their service had become - fortunately they fixed it. And now, it is the hackers abusing the loop holes in the FB APIs. I wish, in this new year (not new decade), FB would take controls of their activities and fix the problems they have been letting others create for them.

Sometimes, I wonder if this is the beginning of Social Media Viruses.I wonder is should I still be moving my contents and my applications to the CLOUD. In my humble opinion, cloud isn't safe as of today. Yes, it can me made safe, but that would add its cost and time.

This also reminds me that I should stay with safe harbors like Solaris and Linux which are rarely affected by such viruses. Also, I think, it is time for private social media rather than open social media.

Happy Safe Surfing!

FREE Workshop: The Six Key Characteristics of Successful Entrepreneurs PDF Print E-mail
Written by Kuldip Pabla   
Friday, 20 November 2009 00:02

"Most successful entrepreneurs figure out how to grow their businesses in ways that you wouldn't find in a business text book. Although there is not one single formula to become a successful entrepreneur, Silver Lining believes that there are six key characteristics that help predict success.

New York entrepreneur network is hosting a free workshop. Here is an exerpt of the event announcement. For more details or go RSVP for this free event, go to http://www.ny-entrepreneur-network.com/calendar/11907025/


Page 1 of 6
Copyright © 2016 KSPTech Inc.. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.