Thursday, September 8, 2011

Reverse Mapping

I have Implemented one more thing and that is Reverse Mapping for iPhone and iPad.Now We can take all information using map like if i click on the map it will returns the latitude and Longitude of that particular Place and using Forward Geocoding we can get the Address of that Particular location.

With iOS 3.2 or greater, it's probably better and simpler to use a UIGestureRecognizer with the map view instead of trying to subclass it and intercepting touches manually.First, add the gesture recognizer to the map view:

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc]
initWithTarget
:self action:@selector(tapGestureHandler:)];
tgr
.delegate = self; //also add to @interface
[mapView addGestureRecognizer:tgr];
[tgr release];

Next, implement shouldRecognizeSimultaneouslyWithGestureRecognizer and return YES so your tap gesture recognizer can work at the same time as the map's
(otherwise taps on pins won't get handled automatically by the map):


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer
:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}


Finally, implement the gesture handler:

- (void)tapGestureHandler:(UITapGestureRecognizer *)tgr
{
CGPoint touchPoint = [tgr locationInView:mapView];

CLLocationCoordinate2D touchMapCoordinate
= [mapView convertPoint:touchPoint toCoordinateFromView:mapView];

NSLog(@"tapGestureHandler: touchMapCoordinate = %f,%f",
touchMapCoordinate
.latitude, touchMapCoordinate.longitude);
}