在 iPhone 中查找最近的地点
各位 iPhone 开发者大家好,
我正在开发一个 iPhone 应用程序。
在此应用程序中,我想找到与我从 iPhone 设备获取的当前 CLLocation 相关的最近位置。
我目前在不同的服务器上有一个数据库。
我通过 .NET Web 服务访问它。
在用于测试目的的数据库中,我创建了一些带有从谷歌地图获取的纬度和经度字段的记录。
现在,我的问题是:
如何确定数据库中的位置是否靠近当前位置(在千米范围内)?
我有以下选择:
如果
- 我必须获取基于地址的 currentLocation.latitude 和 currentLocation.longitude 并传递它 到我比较的服务 与可用的地址(我有 阅读某处“地理编码”)。
否则如果
- 我可以将纬度和经度直接传递给网络服务 并做(我想要什么类型的 如果有人知道的话建议)一些 在那里进行计算并返回 最近的地点数据传回 iPhone。
其他
或者这个解决方案完全是 合乎逻辑,如果有人有解决方案 重新整理它或教程然后它 将会很有用。
Hello all iPhone developers,
I am developing an iPhone application.
In this application i want to find nearest places related to current CLLocation that I am getting from the iPhone device.
I have currently a database in different server .
I am accessing it via .NET web service.
In the database for testing purpose i have created some records with fields of latitude and longitude that I have taken from google maps.
Now ,My Question is that:
How can I determine that the location in the database is near by( within a range of kelometers) the current location ?
I have my options as below:
if
- i have to get a address based and currentLocation.latitude and
currentLocation.longitude and pass it
to the service where i compare it
with the available address ( i have
read somewhere "geocoding").
else if
- i can pass the latitude and longitude directly to the web-service
and do (what type of i want some
suggestion if any one knows) some
calculations there and give back the
nearest places data back to iPhone.
else
or this solution is completely
logical and if anyone have solution
reagrding it or a tutorial then it
will be useful.- i have to get a address based and currentLocation.latitude and
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确实,有很多反向地理编码服务(Google、Yahoo!、GeoNames 等)可以将纬度/经度对转换为街道地址。
但是,如果您的数据库中已经有纬度/经度对,那么我认为您不需要转换为街道地址。如果所有点都由纬度/经度表示,则计算距离会容易得多,您可以使用Haversine 公式。
事实上,如果您的数据库本身支持空间类型(例如, MS SQL 2008 似乎是),然后您可以将该计算推入数据库层,而不必担心它。对我来说,这似乎是正确的方法:让您的 iPhone 应用程序将纬度/经度发送到您的网络服务,并让数据库计算最近的兴趣点。
It's true, there are a lot of reverse geocoding services out there (Google, Yahoo!, GeoNames, etc.) to convert from a lat/lon pair to a street address.
But if you have lat/lon pairs in your database already, then I don't think you ever need to convert to a street address. Calculating distances is much easier if all your points are represented by lat/lon, you can use the Haversine formula.
And in fact, if your database natively supports spatial types (for example, MS SQL 2008 appears to), then you can push that calculation into the database layer and not have to worry about it. That seems like the right approach to me: have your iPhone app send lat/lon to your web service and have the database calculate the nearest points-of-interest.