Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you are referring to is forward geocoding and unfortunately apple has not provided an api for it. However, there is the next best thing, a third party api. Check out this project, I used it successfully in two projects, works great: <a href="https://github.com/bjornsallarp/BSForwardGeocoder" rel="nofollow">https://github.com/bjornsallarp/BSForwardGeocoder</a></p> <p>Make sure you include the files necassary so that you can include BSForwardGeocoder without error. Then, simply make the class you want to use it in a BSForwardGeocoderDelegate, and implement the following two protocol methods in your class:</p> <pre><code>-(void)queryAddress { // Initialize member BSForwardGeocoder object if (forwardGeocoder == nil) { forwardGeocoder = [[BSForwardGeocoder alloc] initWithDelegate:self]; } // send the request [forwardGeocoder findLocation:@"Saint Paul, MN"]; } </code></pre> <p>and:</p> <pre><code>-(void)forwardGeocoderFoundLocation:(BSForwardGeocoder *)geocoder { /* * BSForwardGeocoder delegate method. Receives the callback upon geocoding data gather completion. */ if (forwardGeocoder.status == G_GEO_SUCCESS) { int searchResults = [forwardGeocoder.results count]; for (int i = 0; i &lt; searchResults; i++) { // See the sample project code fore other useful location properties... // Here I retrieve the returned lat and lon. Result *location = [forwardGeocoder.results objectAtIndex:i]; mLatitude = location.latitude; mLongitude = location.longitude; } } else { NSString *message = @""; switch (forwardGeocoder.status) { case G_GEO_BAD_KEY: message =@"Bad Api Key"; break; case G_GEO_UNKNOWN_ADDRESS: message = @"Address Not Found!"; break; case G_GEO_TOO_MANY_QUERIES: message = @"Too Many Queries"; break; default: break; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Information" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [ alert show ]; [ alert release ]; } } </code></pre> <p>This would return the latitude and longitude of Saint Paul, Minnesota using the great library provided by sallarp.</p> <p>If you want to drag annotations around the map and get their coordinate info this is possible as well, you need to make your class a mkmapview delegate and implement the <code>mapView:annotationView:didChangeDragState:fromOldState:</code> method. In your implementation, first check to see if newState is equal to mkAnnotationViewDragStateEnding, if so you can get its coordinate info via the annotationView.annotation.coordinate property. Of course you need to set your annotation views draggable property to YES. If you wanted, you could fire these coordinates in NSString format off to google via the BSForwardGeocoder query method and get it's associated info.</p> <p>Greg</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload