如何实现 Realtor iPad 应用程序中使用的自定义图纸搜索工具?

发布于 2024-11-09 14:22:58 字数 124 浏览 2 评论 0原文

Realtor iPad 应用程序在 Mapkit 之上实现了自定义绘图工具,他们使用该工具来查询房屋区域,这方面做得非常好。我熟悉 Mapkit 及其相关类,但我不知道如何用手指进行一些自定义绘图并将其转换为地理空间查询。怎么做呢?

The Realtor iPad app has done a very good job of implementing a custom drawing tool on top of mapkit that they use to query an area for homes. I am familiar with mapkit and its associated classes but I am unaware of how I could do some custom drawing with my finger and have it translate to a geospatial query. How to do it?

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

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

发布评论

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

评论(1

云雾 2024-11-16 14:22:58

我不确定您已经做到了多远,但您的基本算法应该如下所示:

  • 在地图上方绘制一个多边形,然后将该多边形的坐标转换为“地图”坐标。为此,您可能需要监听 MKMapKit 实例以外的视图上的手势。由于我对 MapKit 触摸事件处理的了解有限,当您想要绘制时,您可能必须在地图上覆盖不同的透明视图,因此触摸事件不会传递到 MapKit(如果这有意义的话)。你用手指进行捏合、缩放、平移,如果你想画画,你就不会需要这些功能。在该视图中,您将绘制跟踪用户手指的形状,然后将绘制的点转换为地图点。

    文档表明您可以使用 MKMapView 上的 convertPoint:toCooperativeFromView: 方法将屏幕点转换为地图点。

    检查此链接以获取相关信息:转换 MapKit 用户坐标时遇到问题到屏幕坐标

    这篇文章提供了一个可以帮助您绘制多边形的链接:
    使用 MapKit 框架在 google 地图上绘制多边形< /p>

  • < p>绘制多边形后,您将需要“空间”查询数据。您可以通过多种方式做到这一点。在设备本地或通过 Web 服务有两种选择。如果您的数据位于设备本地,则必须在设备上进行制图数学计算。您还需要确保点数据(X、Y)与多边形信息位于相同的投影和坐标空间中。当您的投影和坐标系对齐时,多边形相交数学的计算相对简单。

    这是一个可以帮助您进行数学计算的链接。

    https://math .stackexchange.com/questions/237/how-do-you-define-if-a-point-sits-inside-a-polygon

    或者,您可以设置一些 Web 服务,该服务获取多边形数据并在服务器上执行相同的制图数学,并将结果返回到设备。无论哪种方式,都需要执行相同的数学运算。您将获取该多边形数据并确定数据中的哪些记录与该多边形相交。

我知道这是相当高级的,但这应该是您需要做的全部。

另一个考虑因素是您的数据是否通过为设备上的 SQLite 或服务器上的 SQL Server Spatial 编译的 Spatialite 启用了空间功能。您应该能够使用该多边形数据查询数据。不过,您必须正确设置查询格式。

最后,我鼓励您研究一下适用于 iOS 的 ESRI SDK。 ESRI 提供开箱即用的绘图和草图绘制工具。它使用起来不太困难,但一个缺点是您必须学习一种新的 API:

http://resources.arcgis.com/en/communities/runtime-ios-sdk/

I'm not sure how far along you've made it with this, but your basic algorithm should look like this:

  • Draw a polygon overtop your map, then translate the coordinates of that polygon to "map" coordinates. In order to do that you would probably need to listen for gestures on a view other than the MKMapKit instance. With my limited knowledge of the MapKit's touch event handling you might have to overlay a different transparent view on the map when you want to draw, so touch events won't go through to the MapKit (if that makes any sense). You use your finger to pinch, zoom, pan and you won't want that functionality if you're trying to draw. In that view, you'll draw the shape tracing the user's finger, then translate the points drawn into map points.

    The docs indicate that you can translate screen points to map points using the convertPoint:toCoordinateFromView: method on MKMapView.

    Check this link for information on that: Trouble converting MapKit user coordinates to screen coordinates

    This post provides a link that might help you with drawing the polygon:
    To draw polygon on google map with MapKit framework

  • After you've drawn your polygon you'll want to "spatially" query your data. You could do that in several ways. Locally on the device or through a web service are two options. If your data is local to the device you'll have to do the cartographic math on your device. You'll also need to ensure that your point data (the X,Y's) are in the same projection and coordinate space as your polygon's information. Polygon intersection math is relatively straight forward to do, when your projections and coordinate systems line up.

    Here's a link that can help you with the math.

    https://math.stackexchange.com/questions/237/how-do-you-determine-if-a-point-sits-inside-a-polygon

    Alternatively you could set up some web service that takes your polygon data and performs the same cartographic math on a server and returns the results to the device. Either way the same math needs to be performed. You'll take that polygon data and determine which records in your data intersect with that polygon.

This is pretty high-level, I know, but it should be all you need to do.

Another consideration is if your data is spatially enabled with spatialite compiled for SQLite on your device or SQL Server Spatial on your server. You should be able to query the data using that polygon data. You would have to format the query properly, though.

Lastly, I would encourage you to look into the ESRI SDK for iOS. ESRI provides drawing and sketching tools out of the box. Its not too difficult to use but one downside is that you would have to learn a new API:

http://resources.arcgis.com/en/communities/runtime-ios-sdk/

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