Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:49:50+00:00 2026-06-12T21:49:50+00:00

So I’m trying to get a CLLocation based on touching a MKMapView. I’m then

  • 0

So I’m trying to get a CLLocation based on touching a MKMapView. I’m then trying to reverse geocode the location.

    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        // Not sure if this is the right method to get the location or not
        CLLocationCoordinate2D coordinate = [self.mapView convertPoint:[gestureRecognizer locationInView:self.mapView] toCoordinateFromView:self.mapView];

        CLLocation *pinLocation = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];

        [geocoder reverseGeocodeLocation:pinLocation completionHandler:^(NSArray *placemarks, NSError *error) {
            if (placemarks && placemarks.count > 0) {
                CLPlacemark *topResult = [placemarks objectAtIndex:0];
                AddressAnnotation *anAddress = [[AddressAnnotation alloc] initWithPlacemark:topResult];     

                [self.mapView addAnnotation:anAddress];
                [self.addressesArray addObject:anAddress];
            }
            else {
                AddressAnnotation *anAddress = [[AddressAnnotation alloc] initWithCoordinate:coordinate];
                [self.mapView addAnnotation:anAddress];
                [self.addressesArray addObject:anAddress];
            }
        }];

With my if/else statement, what I want to do is touch the map and get the CLLocation. If I can reverse geocode the location, drop the pin with the address. If I can’t reverse geocode the location, then drop the pin and just show the latitude and longitude in the map callout.

It doesn’t seem to work. It seems like even though I touch the map at a certain location, the reverse geocoding makes my pin go somewhere else where the reverse geocode can locate the location. This isn’t the behavior I want though. I want to drop the pin no matter what, and if I can’t show the address in the callout, just show the lat/long.

If I remove the revseGeocodeLocation:pinLocation code altogether, and just use what’s in the else block, then I get the lat/long and the pin gets dropped there no matter what. Is there a reason why the reverse geocoder stops me from dropping the pin where I want?

As a side note, can anyone confirm if the way I calculate the CLLocationCoordinate2D based on the UITapGestureRecognizer correct?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:49:51+00:00Added an answer on June 12, 2026 at 9:49 pm

    The coordinate calculation based on the tap point looks correct.

    The problem is that when coordinate is reverse-geocoded, the placemark returned may be some place near those coordinates and the CLPlacemark object itself (topResult) contains that place’s exact coordinates in topResult.location.coordinate (which is the coordinate that the annotation is using when created using initWithPlacemark).

    Unless the user happens to tap exactly on a reverse-geocode-able coordinate, the placemark will not be exactly where they tapped.

    Since you want to place the pin exactly where the user tapped regardless of the nearest found placemark, what you can do is override the coordinate used by AddressAnnotation when it is initialized using a placemark.

    For example, after calling initWithPlacemark (assuming that method sets the annotation’s coordinate property using the placemark’s location), you could afterwards override it:

    AddressAnnotation *anAddress = [[AddressAnnotation alloc] initWithPlacemark...
    anAddress.coordinate = coordinate; // <-- replace with tapped coordinate
    

    Alternatively, you could use initWithCoordinate instead and set the title, etc manually using the information from topResult.

    Also, if the placemark found is more than some distance x from the tapped coordinate, consider adding a prefix such as “Near ” in front of the title/subtitle to indicate to the user that the pin is not exactly at the tapped location (eg. “Near Eiffel Tower”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.