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 5937649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:34:19+00:00 2026-05-22T15:34:19+00:00

friends, as we have geocoder getfromlocation(locationname,maximumResults) function of google api in android. i dont

  • 0

friends,

as we have geocoder getfromlocation(locationname,maximumResults) function of google api in android.

i dont see such function in iphone sdk to obtain latitude and longitude values from city name.

any one guide me how to achieve this functionality?
any help would be appreciated.

  • 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-05-22T15:34:20+00:00Added an answer on May 22, 2026 at 3:34 pm

    iOS <5

    There is no geocoding API. You need to ask Google:
    http://maps.googleapis.com/maps/api/geocode/json?address=YOURADDRESS&sensor=true and parse the result using JSONKit.

    Something like this:

    -(CLLocation*) geocodeAddress:(NSString*) address {
    
        NSLog(@"Geocoding address: %@", address);
    
        // don't make requests faster than 0.5 seconds
        // Google may block/ban your requests if you abuse the service
        double pause = 0.5;
        NSDate *now = [NSDate date];
        NSTimeInterval elapsed = [now timeIntervalSinceDate:self.lastPetition];
        self.lastPetition = now;
        if (elapsed>0.0 && elapsed<pause){
            NSLog(@"    Elapsed < pause = %f < %f, sleeping for %f seconds", elapsed, pause, pause-elapsed);
            [NSThread sleepForTimeInterval:pause-elapsed];
        }
    
        // url encode
        NSString *encodedAddress = (NSString *) CFURLCreateStringByAddingPercentEscapes(
                                    NULL, (CFStringRef) address,
                                    NULL, (CFStringRef) @"!*'();:@&=+$,/?%#[]",
                                    kCFStringEncodingUTF8 );
    
        NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", encodedAddress];
        //NSLog(@"    url is %@", url);
        [encodedAddress release];
    
        // try twice to geocode the address
        NSDictionary *dic;
        for (int i=0; i<2; i++) { // two tries
    
            HttpDownload *http = [HttpDownload new];
            NSString *page = [http pageAsStringFromUrl:url];
            [http release];
            dic = [JsonParser parseJson:page];
            NSString *status = (NSString*)[dic objectForKey:@"status"];
            BOOL success = [status isEqualToString:@"OK"];
            if (success) break;
    
            // Query failed
            // See http://code.google.com/apis/maps/documentation/geocoding/#StatusCodes
            if ([status isEqualToString:@"OVER_QUERY_LIMIT"]){
                NSLog(@"try #%d", i);
                [NSThread sleepForTimeInterval:1];
            } else if ([status isEqualToString:@"ZERO_RESULTS"]){
                NSLog(@"    Address unknown: %@", address);
                break;
            } else {
                // REQUEST_DENIED: no sensor parameter. Shouldn't happen.
                // INVALID_REQUEST: no address parameter or empty address. Doesn't matter.
            }
    
        }
    
        // if we fail after two tries, just leave
        NSString *status = (NSString*)[dic objectForKey:@"status"];
        BOOL success = [status isEqualToString:@"OK"];
        if (!success) return nil;
    
        // extract the data
        {
            int results = [[dic objectForKey:@"results"] count];
            if (results>1){
                NSLog(@"    There are %d possible results for this adress.", results);
            }
        }
    
        NSDictionary *locationDic = [[[[dic objectForKey:@"results"] objectAtIndex:0] objectForKey:@"geometry"] objectForKey:@"location"];
        NSNumber *latitude = [locationDic objectForKey:@"lat"];
        NSNumber *longitude = [locationDic objectForKey:@"lng"];    
        NSLog(@"    Google returned coordinate = { %f, %f }", [latitude floatValue], [longitude floatValue]);
    
        // return as location
        CLLocation *location = [[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue]];
    
        return [location autorelease];
    }
    
    +(NSDictionary*) parseJson:(NSString*) jsonString {
    
        NSDictionary *rootDict = nil;
        NSError *error = nil;
        @try {
            JKParseOptionFlags options = JKParseOptionComments | JKParseOptionUnicodeNewlines;
            rootDict = [jsonString objectFromJSONStringWithParseOptions:options error:&error];
            if (error) {
                warn(@"%@",[error localizedDescription]);
            }
            NSLog(@"    JSONKit: %d characters resulted in %d root node", [jsonString length], [rootDict count]);
    
        } @catch (NSException * e) {
            // If data is 0 bytes, here we get: "NSInvalidArgumentException The string argument is NULL"
            NSLog(@"%@ %@", [e name], [e reason]);
    
            // abort
            rootDict = nil;
        }
        return rootDict;
    }
    

    iOS >= 5

    iOS 5 has a geocoder API:

    CLGeocoder* gc = [[CLGeocoder alloc] init];
    [gc geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) 
    {
        if ([placemarks count]>0) 
        {
            // get the first one
            CLPlacemark* mark = (CLPlacemark*)[placemarks objectAtIndex:0];
            double lat = mark.location.coordinate.latitude;
            double lng = mark.location.coordinate.longitude;            
        }
    }];
    

    The CLPlacemark object has the following properties:

    • name
    • addressDictionary: Address Book keys and values for the placemark.
    • ISOcountryCode
    • country
    • postalCode
    • administrativeArea
    • subAdministrativeArea
    • locality
    • subLocality
    • thoroughfare: Street address.
    • subThoroughfare: Address Book keys and values for the placemark.
    • region
    • inlandWater
    • ocean
    • areasOfInterest
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my Android program List<Address> addressList = geoCoder.getFromLocation(37.790551,-122.433931, 1);
I have two JSON objects here, generated through the Google Search API. The URL's
Hello friends I have the following script in my Template: window.addEvent('domready', function () {
I have two professional programmer friends who are going to teach me, and they
I have a working WAMP environment (Apache Friends). I decided to try Subversion and
I have a database table that i want to allow my friends to update.
friends, i have created custom title bar using following titlebar.xml file with code <?xml
Friends, I have a strange need and cannot think my way through the problem.
friends, i have a EditText on simple activity with a button. when every i
I have a Person class. A person class contains a collection of Friends (also

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.