I am interested in adding an option to my GIS Map application, the ability to draw Polygon, circle, polyroutes overlays for the user to search data within.The problem is that I've read and tested codes of how to draw an overlay, but they are always static.I want it to be dynamic, with dynamic center and points (or radius) set by the user on click.A mystery for me.(I'm a beginner in iPhone programming, this is my first app.)And I'm not using and don't want to use things like ArcGIS API for iPhone.I would appreciate any help.
-
By "dynamic", do you mean you want to change the overlay without removing it and adding it again? Give a specific example of what you need and what you've tried. – Sep 07 '11 at 14:47
-
By dynamic, I mean this: I want the user to be able to search for some businesses (f.e.) inside a polygon area, but this area should be decided by the user itself, he should be able to select the polygon option, add one point, another, another, until he forms his desired area, and the polygon's corners (with the polygon now formed) should be draggable in the map (therefore changing its form).Hope I've been a little more clear.The problem is that I don't know how to create a polygon with not known number of corners and not known position of corners.Thank you for any answer. – Hari Sep 07 '11 at 19:34
1 Answers
To let the user "draw" an arbitrary polygon on the map, one approach is to use draggable annotations that represent the corners of the polygon. Provide an "Add Corner" button and some kind of Remove Corner button on each annotation.
See my answer to User creating a box on MKMapView for some more details. On that question though, the OP actually ended up using another solution described in the comments which would work well if the polygons are always rectangles.
For implementing a button in an annotation view (if you want a "Remove Corner" button on the annotations), see my answer to How to get click event from a button added over MKAnnotationView.
Once you a have a polygon or other overlay on the map, dragging it by direct touches may only be possible by adding a gesture recognizer to the map (with its own scrolling turned off) and using a custom MKOverlay and MKOverlayView that allow coordinate changes. Adding a gesture recognizer directly to an MKOverlayView doesn't seem to work and the built-in overlay classes don't allow changes to coordinates.
An alternative to moving by direct touches is putting some controls on the side (Up/Down/Left/Right/etc buttons) that modify the custom overlay.
The Apple sample app Breadcrumb gives an example of a custom overlay/view for a path. In WWDC 2010, the sample app LocationReminders gives an example of a custom overlay/view for a circle that can move and resize.
Finally, when you do a search for businesses, you could use the overlay's boundingMapRect (which is always a rectangle regardless of the overlay's shape) as the bounding box for the initial search and then check if the coordinate of each business found is in the overlay's actual shape using the answer to How to determine if an annotation is inside of MKPolygonView (iOS).

- 1
- 1
-
Thank you very, very much for being so kind with your answer!I'll try those "hints" as soon as i can.Sorry for responding so late, but I am having exams right now, and didn't have so much time to work with this.Commenting the results soon... – Hari Sep 14 '11 at 21:22