Bing 或 GMaps API 可以执行“查找最近的”功能吗?使用提供的 XML/RSS 集合进行样式搜索?

发布于 2024-08-24 06:38:50 字数 114 浏览 3 评论 0原文

Bing 或 Google 地图是否可以允许您传递点集合,然后询问该集合以仅绘制 X 个最近的点?

我之所以这么问,是因为预过滤这些数据可能很困难,而提供整个列表并在 API 本身中过滤它会更简单。

Can either Bing or Google Maps allow you to pass in a collection of points and then interrogate that collection to only plot the X nearest points?

I am asking because it may be difficult to pre-filter this data and would be much simpler to supply the entire list and filter it within the API itself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心房敞 2024-08-31 06:38:50

您必须自己完成大部分跑腿工作,API 不会为您完成所有功能。

不过,我知道您可以使用 Google Maps API 找到两点之间的距离。查看 中的 distanceFrom 方法API 参考。只需计算 XML 文件中每个点的距离,然后取最小的 X 数字即可。

关于您的评论 - 是的,我想在客户端循环 300 个项目可能有点多。一种解决方案是将每个点的 GPS 坐标存储在 XML 文件中(如果还没有),然后创建一个函数,使用简单的距离计算器删除大部分点(您必须自己研究)。然后将剩余的点(可能是 30 个)传递到 API 中以计算更准确的距离。

You'd have to do most of the legwork yourself, the APIs aren't going to do every function under the sun for you.

However, I know that you can find the distance between two points using the Google Maps API. Take a look at the distanceFrom method in the API reference. It would only be a matter of calculating the distances for every point in your XML file, then taking the smallest X numbers.

Regarding your comment - yeah I guess looping through 300 items on the client-side might be a bit much. One solution would be to store the GPS coordinates for each point in your XML file (if not already), then create a function that would prune away most of the points using a simple distance calculator (you'd have to research that yourself). Then pass the remaining points (maybe 30 of them) into the API to calculate more accurate distances.

℉服软 2024-08-31 06:38:50

我只是想根据我收到的客户请求执行此操作。据我所知,最好的方法是使用Google(或类似的)对您输入的地址进行地理编码(即将邮政地址转换为纬度和经度)。

当您要“查找最近的”时,您可能需要获取搜索者的邮政编码,然后对其进行地理编码,或者如果您能够直接从手机中获取数据,则可能需要进行经纬度编码设备。

一旦您获得了固定位置的经纬度,并且您的用户也获得了相同的经纬度,我认为您可以使用 半正矢公式(我这么说,但我实际上没有尝试过 - 我不是数学家),这是一种计算球体周围两点之间距离的数学方法。地球并不完全是一个球体,但对于这种目的来说已经足够近了。

这样,您只需对外部服务进行一次查找即可找到您的用户位置(假设您在创建固定点时对固定点进行了地理编码,并存储它们供以后使用),然后在服务器端进行驴工作来计算距离。您甚至可以创建一个自定义 SQL 函数来按顺序将其从数据库中提取出来。

I'm just looking at doing this for a client request i've had. As far as I can see, the best way to do it would be to use Google (or similar) to Geocode your addresses when they're entered (that is, turn a postal address into a latitude and longitude).

When you come to 'find my nearest', you'll want to get a postcode (probably) of the person searching and then geocode it, or maybe a lat-long if you're able to get the data straight out of a mobile device.

Once you have the lat-long for your fixed positions, and the same for your user, I reckon you can use a haversine formula (I say this, but I haven't actually tried it - I'm no mathematician) which is a mathematical way of calculating the distance between two points around a sphere. The Earth isn't quite a sphere, but close enough for this sort of purpose.

This way, you're only doing one lookup to an external service to find your users location (assuming you've geocoded your fixed points when they were created, and stored them for later), and then doing the donkey work server side to calculate the distances. You could probably even create a custom SQL function to pull it right out of the database in order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文