从给定的邮政编码获取给定半径(km)内的所有邮政编码 [英] Getting all Zip Codes in a given Radius(km) from given Zip code
问题描述
i我的数据库包含所有邮政编码,纬度和地址,这里我的要求是,
如果我给了Zip码和Radius,我需要从我的数据库获取该地区的所有邮政编码。
i搜索它,但我从 https://developers.google.com/maps/documentation/javascript/tutorial [ ^ ],
i不需要API,我只想从我的SQL数据库表中得到结果。
任何想法,
在此先感谢
i have my database with all Zip codes, latitudes and long address, here my requirement is,
if i given Zip code and Radius , i need to get all Zip Codes in that Region from My database only.
i searched it, but i got google API from https://developers.google.com/maps/documentation/javascript/tutorial[^],
i don't need API , i just want my results from my SQL database table only.
Any Ideas,
Thanks In advance
推荐答案
以英里为单位
reslts in miles
SELECT id, ( 3959 * acos( cos( radians(YOUR_LATITUDE) ) * cos( radians( YOUR_DB_LAT_FIELD ) ) * cos( radians( YOUR_DB_LNG_FIELD )
- radians(YOUR_LONGITUDE) ) + sin( radians(YOUR_LATITUDE) ) * sin( radians( YOUR_DB_LAT_FIELD ) ) ) ) AS distance
FROM YOUR_DB_TABLE HAVING distance < 25 ORDER BY distance ASC;
YOUR_LATITUDE和YOUR_LONGITUDE是您输入的地方邮政编码的值YOUR_DB_LAT_FIELD和YOUR_DB_LNG_FIELD是包含数据库中每个邮政编码的经度和纬度值的字段,最后YOUR_DB_TABLE是您要查询的数据库表。 距离< 25告诉数据库只返回小于25英里的值。您可以修改或省略此项以返回全部。
YOUR_LATITUDE and YOUR_LONGITUDE are where you enter the values of your ZIP code, YOUR_DB_LAT_FIELD and YOUR_DB_LNG_FIELD are the fields containing the longitude and latitude values for each ZIP code in your database, and finally YOUR_DB_TABLE is the database table you are querying. "distance < 25″ tells the database to only return values that are less than 25 miles away. You can modify or omit this to return all.
这篇关于从给定的邮政编码获取给定半径(km)内的所有邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!