如何实现 Realtor iPad 应用程序中使用的自定义图纸搜索工具?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您已经做到了多远,但您的基本算法应该如下所示:
在地图上方绘制一个多边形,然后将该多边形的坐标转换为“地图”坐标。为此,您可能需要监听 MKMapKit 实例以外的视图上的手势。由于我对 MapKit 触摸事件处理的了解有限,当您想要绘制时,您可能必须在地图上覆盖不同的透明视图,因此触摸事件不会传递到 MapKit(如果这有意义的话)。你用手指进行捏合、缩放、平移,如果你想画画,你就不会需要这些功能。在该视图中,您将绘制跟踪用户手指的形状,然后将绘制的点转换为地图点。
文档表明您可以使用 MKMapView 上的
convertPoint:toCooperativeFromView:
方法将屏幕点转换为地图点。检查此链接以获取相关信息:转换 MapKit 用户坐标时遇到问题到屏幕坐标
这篇文章提供了一个可以帮助您绘制多边形的链接:
使用 MapKit 框架在 google 地图上绘制多边形< /p>
这是一个可以帮助您进行数学计算的链接。
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/