许多基于位置的服务都提供了用于查找给定纬度经度对周围的地点/地点/地点的 API。我正在研究如何在整个城市中搜索这些地方。
我可以通过从谷歌地图地理编码器获取城市的边界,然后增加纬度/经度以放置点以形成网格来为城市构建网格。我已经制作了这个网格的原型(单击“填充网格”按钮查看所有点)以可视化这个想法。
// gather a collection of lat/long pairs that represents a grid of the city
var latIncrement = .04;
var lngIncrement = .04;
var newLat = nw.lat();
while(newLat >= sw.lat()) {
var newLng = nw.lng();
while(newLng <= ne.lng()) {
// western and northern border as well as grid infill
addMarker(new google.maps.LatLng(newLat, newLng));
newLng += lngIncrement;
}
// eastern border
addMarker(new google.maps.LatLng(newLat, ne.lng()));
newLat -= latIncrement;
}
// southern border
var newLng = sw.lng();
while(newLng <= se.lng()) {
addMarker(new google.maps.LatLng(sw.lat(), newLng));
newLng += lngIncrement;
}
addMarker(se);
然后,我可以获取所有这些点并针对 LBS API 运行搜索。
我的问题是,有没有更科学的方法/算法来建立这个网格?我想了解更多关于他们的信息。我只是任意增加纬度/经度,直到到达网格的边界。地方的密度会因城市和城市面积而有很大差异,因此增量有时会太小,有时会太大。我正在寻找有关如何更好地调整它的想法?