Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Finding nearby businesses
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
quesnelj  
View profile  
 More options Nov 2, 1:18 pm
From: quesnelj <quesnel.jacq...@gmail.com>
Date: Sun, 1 Nov 2009 18:18:39 -0800 (PST)
Local: Mon, Nov 2 2009 1:18 pm
Subject: Finding nearby businesses
Greetings,

I'm very new at Google API, and thus am not to sure where to start.

I have a DB containing business location addresses entered by clients.
I want other clients to enter a zip code and have my application
return all businesses in my DB that is physically near (20miles,
30miles, 40miles, ...) the entered zip. Displaying on a map would be
nice, but not mandatory.

Could you please give me an idea of what my options may be.

Regards,

Jacques


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rossko  
View profile  
 More options Nov 2, 8:45 pm
From: Rossko <ros...@culzean.clara.co.uk>
Date: Mon, 2 Nov 2009 01:45:04 -0800 (PST)
Local: Mon, Nov 2 2009 8:45 pm
Subject: Re: Finding nearby businesses

> I have a DB containing business location addresses entered by clients.
> I want other clients to enter a zip code and have my application
> return all businesses in my DB that is physically near (20miles,
> 30miles, 40miles, ...) the entered zip. Displaying on a map would be
> nice, but not mandatory.

The classic example of using db with maps for 'search nearby'
http://googlemapsapi.blogspot.com/2008/01/article-creating-store-loca...

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
quesnelj  
View profile  
 More options Nov 9, 4:59 am
From: quesnelj <quesnel.jacq...@gmail.com>
Date: Sun, 8 Nov 2009 09:59:16 -0800 (PST)
Local: Mon, Nov 9 2009 4:59 am
Subject: Re: Finding nearby businesses
I have not completely read the article yet, but looks like what I've
been searching. Thank you. If any one comes up with a classic ASP and
MS SQL that would be the best. For now, I'll check this out and hope
for the best.

Thanks again...

Jacques

On Nov 2, 4:45 am, Rossko <ros...@culzean.clara.co.uk> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
quesnelj  
View profile  
 More options Nov 11, 8:38 am
From: quesnelj <quesnel.jacq...@gmail.com>
Date: Tue, 10 Nov 2009 13:38:40 -0800 (PST)
Local: Wed, Nov 11 2009 8:38 am
Subject: Re: Finding nearby businesses
Greetings,

The MySQL statement:

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin
( radians( lat ) ) ) ) AS distance
FROM markers
HAVING distance < 25
ORDER BY distance

Does not work with MS SQL Server as "distance" cannot be used in the
HAVING and ORDER BY clauses.

Does any one have a suggestion?

Thank you,

Jacques

On Nov 8, 12:59 pm, quesnelj <quesnel.jacq...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Leach  
View profile  
 More options Nov 11, 9:12 am
From: Andrew Leach <andrew.leac...@googlemail.com>
Date: Tue, 10 Nov 2009 14:12:36 -0800 (PST)
Local: Wed, Nov 11 2009 9:12 am
Subject: Re: Finding nearby businesses
On Nov 10, 9:38 pm, quesnelj <quesnel.jacq...@gmail.com> wrote:

> The MySQL statement:

> SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) *
> cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin
> ( radians( lat ) ) ) ) AS distance
> FROM markers
> HAVING distance < 25
> ORDER BY distance

> Does not work with MS SQL Server as "distance" cannot be used in the
> HAVING and ORDER BY clauses.

> Does any one have a suggestion?

As you say, different SQL dialects accept different things. You could
try replacing the keyword HAVING with WHERE -- MySQL can't accept
aliases in the WHERE clause but will allow HAVING; SQL Server doesn't
like HAVING but might allow WHERE with an alias. Otherwise you need to
put your calculation in the WHERE clause, which is far less efficient
but certain to work:

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin
( radians( lat ) ) ) ) AS distance
FROM markers
WHERE ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin
( radians( lat ) ) ) ) < 25
ORDER BY distance

Andrew


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
quesnelj  
View profile  
 More options Nov 12, 6:46 am
From: quesnelj <quesnel.jacq...@gmail.com>
Date: Wed, 11 Nov 2009 11:46:51 -0800 (PST)
Local: Thurs, Nov 12 2009 6:46 am
Subject: Re: Finding nearby businesses
Hello there,

MS SQL doesn't mind the HAVING clause, it just doesn't like using
anything it renames through an AS clause, which is odd to me.

Yes, repeating the calculation in the WHERE clause would work, but I'd
also need to repeat it in the ORDER BY clause. Considering the
calculation to be heavy, I find this to be excessive, and really
inefficient. I might try doing this using a stored procedure. I think
that might be doable...

I wonder if MS SQL is smart enough to recognize that the second and
third calculations are repeats, and actually only do it once?

Thanks,

Jacques

On Nov 10, 5:12 pm, Andrew Leach <andrew.leac...@googlemail.com>
wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
quesnelj  
View profile  
 More options Nov 15, 1:24 pm
From: quesnelj <quesnel.jacq...@gmail.com>
Date: Sat, 14 Nov 2009 18:24:48 -0800 (PST)
Local: Sun, Nov 15 2009 1:24 pm
Subject: Re: Finding nearby businesses
I have created a stored procedure that seems to do the trick. Here it
is:

/*
This stored proceedure will:
        -Go through a list of addresses stored in a DB table (markers)
        -Calculate the distance of these addresses to the latitude and
longitude passed as parameters
        -Then should the distance be less or equal to the radius parameter,
then the address is inserted into a temporary table
        -Then data is spewed out as a recordset.
All this is based on the Haversine formula. More info on the formula
can be found at:  http://en.wikipedia.org/wiki/Haversine_formula
*/
CREATE PROC dbo.test
        @parmLat float,
        @parmLng float,
        @parmRaduis float
AS
        DECLARE @id int
        DECLARE @name varChar (60)
        DECLARE @address varChar (60)
        DECLARE @lat float
        DECLARE @lng float
        DECLARE @distance float
        DECLARE cr_markers CURSOR FOR SELECT id, name, address, lat, lng FROM
markers -- Populate a recordset with all addresses.

        CREATE TABLE #tmpMarkers (tmpId int, tmpName varChar (60), tmpAddress
varChar (60), tmpLat float, tmpLng float, tmpDistance float) -- Create
a table to hold the addresses we want to keep.

        OPEN cr_markers
        FETCH NEXT FROM cr_markers INTO @id, @name, @address, @lat, @lng
        WHILE @@FETCH_STATUS = 0 -- Loop through all addresses.
                BEGIN
-- 6371 K
-- 3959 Miles
                        SET @distance = (3959 * acos (cos (radians (@parmLat)) * cos
(radians (@lat)) * cos (radians (@lng) - radians (@parmLng)) + sin
(radians (@parmLat)) * sin (radians (@lat)))) -- A bit of trginometry
to calculate the distance of things. Haversine formula.
                        IF @distance <= @parmRaduis -- If it is not too far, then ...
                                BEGIN -- Add the data to our temporary table.
                                        INSERT INTO #tmpMarkers (tmpId, tmpName, tmpAddress, tmpLat,
tmpLng, tmpDistance) VALUES (@id, @name, @address, @lat, @lng,
@distance)
                                END

                        FETCH NEXT FROM cr_markers INTO @id, @name, @address, @lat, @lng
                END
        CLOSE cr_markers -- Get ride of a few things.
        DEALLOCATE cr_markers -- Get ride of a few things.

        SELECT * FROM #tmpMarkers ORDER BY tmpDistance -- Spew
GO

If you have any comments or ways to optimize this, please reply to me
directly, as I don't really monitor this group.

Thank you all for you assistance.

Jacques Quesnel

On Nov 10, 4:38 pm, quesnelj <quesnel.jacq...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google