almost 5 years ago
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;
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)