开发者

How mapping of cities in a country-map is done? ( so users can search for ads nearby their cities )

I have a classifieds website. The users first have to specify their 'area of search'...

I want to add a function wher开发者_开发问答e users also can check a checkbox to find ads 'close' to their selected 'area'.

But I don't know how to 'mapp' or 'link' the areas together in a smart way. I need some advice on how to do this...

For example, how is 'radius search of miles' done on websites where you can search for classifieds?

Thanks

BTW Im using PHP to query MYSQL for results. And currently all areas have their respective names in the field (Nevada = Nevada in the table field value also) So the query is done by getting the value of a drop list and search for that value in the mysql table.


You will have to use radius search script for that. Also you need some database of counties/cities with info in it such as city/country, longitute, latiture, etc.

There are quite some radius search scripts out there, you need to google a bit to find one.


The following link is written specifically for Microsoft SQL Server, but I suspect it wouldn't be too difficult to convert it to MySQL.

ZIP code Latitude/Longitude proximity search


This is the one we use. Sql Server again but very easy to amend.

Lots of other examples on the web gave dodgy results....

ALTER function [dbo].[udf_Haversine](@lat1 float, @long1 float, @lat2 float, @long2 float) returns float begin
    declare @dlon float, @dlat float, @rlat1 float, @rlat2 float, @rlong1 float, @rlong2 float, @a float, @c float, @R float, @d float, @DtoR float

    select @DtoR = 0.017453293
    select @R = 3937 --3976

    select 
        @rlat1 = @lat1 * @DtoR,
        @rlong1 = @long1 * @DtoR,
        @rlat2 = @lat2 * @DtoR,
        @rlong2 = @long2 * @DtoR

    select 
        @dlon = @rlong1 - @rlong2,
        @dlat = @rlat1 - @rlat2

    select @a = power(sin(@dlat/2), 2) + cos(@rlat1) * cos(@rlat2) * power(sin(@dlon/2), 2)
    select @c = 2 * atn2(sqrt(@a), sqrt(1-@a))
    select @d = @R * @c

    return @d 
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜