Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Fetching Latitude and Longitude On Basis Of Address

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 163
    Comment on it

    Hello Friends,

    In order to fetch the latitude and longitude of a location based on its address,you may use the following code:
     

    double latitude = 0;
    
    double longitude = 0;

    Use the google api along with your address

     NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", @"Your address "];

    Connect to the api and the result is stored here in result variable
     

    NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
        if (result) {
            NSScanner *scanner = [NSScanner scannerWithString:result];
            if ([scanner scanUpToString:@"\"lat\" :" intoString:nil] && [scanner scanString:@"\"lat\" :" intoString:nil]) {
                [scanner scanDouble:&latitude];
                if ([scanner scanUpToString:@"\"lng\" :" intoString:nil] && [scanner scanString:@"\"lng\" :" intoString:nil]) {
                    [scanner scanDouble:&longitude];
                }
            }
        }

    Creating location coordinate on the basis of the fetched latitude and longitude

      

     CLLocationCoordinate2D center;
        center.latitude=latitude;
        center.longitude = longitude;

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: