You could use UIButtons to represent the cities. Then you'll get the standard touch, highlight, etc, behaviors with less effort. Adding the buttons as subviews on your map should cause them to scale and scroll along with the map.
I thought about that, but figured with 50+ city points, it would be crazy to declare/manage so many objects. Thanks for responding though - Mike. – user146526 Aug 2 '09 at 23:22 While it might seem crazy, you could just iterate through your dictionary, pull out the city's point, create a new button about 15px by 15px, and then setCenter with the point of the city.
The other thing you'd need to do is wire up the button to a method (addTarget:action:forControlEvent:), and make sure you have a way of recognizing which button corresponds to which city. One way to do that is to set the tag property of the button to be the index of the city in an array. – Dave DeLong 26 Aug at 3:14 Thanks Dave, that is basically what I did.
I iterate through a dictionary of points doing a compound if statement compare (+/- 10) and then when I find a point within tolerance, I pull the name of the city from the dictionary and create/display a view with the city name and a few buttons for user actions. - Thanks again, Mike – user146526 Aug 4 '09 at 11:15 Thanks to everyone who responded, my solution is posted above in response to Dave's suggestions. - Mike – user146526 Aug 4 '09 at 11:17.
If I understand it correctly, you want to know if the point at which the user tapped is "close" enough to a point that is marked as a city. You would have to quantify close i.e. Set a threshold value after which the tap is farther, before which the tap is closer.
Once you do that, calculate the cartesian coordinate distance sqrt ( (x1-x2)^2 + (y1-y2)^2) for each element ( read dictionary with x,y values for cities) in the array and store the results in another array. Then take the minimum of the result. The index of that result is the city that is closest to the tap if it is lesser than the said threshold.
You can either use an R-Tree, or you can calculate the proximity of the touch to each visible point in the current view. To calculate the proximity you would normally use the Pythagorean theorem but in this case you can skip the square-root because you're only comparing the relative sizes. Also you can declare a distance cut off if you like say 50 pixels squared to 2500.So you'd put the result into an object containing distance and reference point and put the objects in an NSMutableArray, not adding the results under your cutoff, and select the minimum result.
So if you have a touched point pT, then for each point pN, you'd calculate: d=(pT. X-pN. X)*(pT.
X-pN. X) + (pT. Y-pN.
Y)*(pT. Y-pN. Y); //d is the squared distance The point pN with the minimum d is the point that was closest to pT.
And like I said if you want only touches within 10 pixels to count, you can test that d.
1 Thanks for the advice, but I can barely spell Pythagorean, never mind understand it. You are obviously one of the smart kids and I was one of the dummy's that skipped math. After taking my dogs for a walk to clear my head, I actually thought of a solution to compare the touch x and y coordinates to a dictionary of stored city x and y coordinates +/- 10 points.
If ( (touchPoint. Y >= (mapPoint. Y -10) && touchPoint.
Y = (mapPoint. X -10) && touchPoint. X X +10)) ) { // do something } Thanks for taking the time to respond - Mike.
– user146526 Aug 2 '09 at 23:19.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.