Google 地图按自定义区域搜索地址
我有一个地址数据库,我希望能够让用户在地图上放置一个精确点,并根据该点周围的行驶距离定义一个区域。我想知道是否有一种方法可以通过该用户定义的区域搜索我的数据库。
I have a database of addresses and I want to be able to have a user drop a pinpoint on the map and define a region based on driving distance around that point. I was wondering if there was a way to search my database by that user defined region.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于使用公里的国际系统,请将脚本的一部分替换为以下脚本:
来源:http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe#MySQL
For the International System that uses Kilometers, replace a part of the script with this one:
Source: http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe#MySQL
您应该能够获取图钉掉落的经度和纬度坐标,然后将该数据发送到您的服务器并使用此页面上列出的查询返回结果:http://code.google.com/apis/maps/articles/phpsqlsearch.html
选择 id, ( 3959 * acos(余弦(弧度(37) ) * cos( 弧度( 纬度 ) ) * cos( 弧度( lng ) - 弧度(-122) ) + sin( 弧度(37) ) * sin( 弧度( 纬度 ) ) ) ) AS 与标记的距离距离< 25 ORDER BY distance LIMIT 0 , 20;
您还需要将地址地理编码为经度和纬度,并将它们与每个地址一起存储。这是我用来抓取数据库中地址的经度和纬度的确切代码:
XML2array 函数: http://www.bin-co.com/php/scripts/xml2array/
You should be able to get the longitude and latitude coordinates of the pin drop, then send that data to your server and return a result using the query listed on this page: http://code.google.com/apis/maps/articles/phpsqlsearch.html
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 LIMIT 0 , 20;
You would need to geocode your addresses into longitude and latitudes as well, and store them with each address though. This is the exact code I used to scrape longitude and latitudes for addresses in my database:
XML2array function: http://www.bin-co.com/php/scripts/xml2array/