Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement the custom drawing search tool used in the Realtor iPad app?

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?

like image 444
kyleplattner Avatar asked Nov 14 '22 22:11

kyleplattner


1 Answers

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/

like image 57
Aaron Avatar answered Dec 21 '22 07:12

Aaron