I got the current location based on Longitude and latitude values and then I also got Multiple places on google map using Annotation now I want get longitude and latitude
It will be as simple as something like this:
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder geocodeAddressString:@"ZIP CODE HERE" completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"Latitude %f", coordinate.latitude);
NSLog(@"Longitude %f", coordinate.longitude);
}];
this is the method for call google map api for geocoding, if u pass the Zipcode/Postal code, you get the result
-(void)ViewDidLoad
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@",yourzipcodetext/PostalcodeText.text]]];
[request setHTTPMethod:@"POST"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
NSLog(@"got response==%@", resSrt);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];
NSString *lataddr=[[[[[dict objectForKey:@"results"] objectAtIndex:0]objectForKey:@"geometry"]objectForKey:@"location"]objectForKey:@"lat"];
NSString *longaddr=[[[[[dict objectForKey:@"results"] objectAtIndex:0]objectForKey:@"geometry"]objectForKey:@"location"]objectForKey:@"lng"];
NSLog(@"The resof latitude=%@", lataddr);
NSLog(@"The resof longitude=%@", longaddr);
}
Chioce-2
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder geocodeAddressString:@"ZIP CODE HERE" completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
NSLog(@"Latitude %f", coordinate.latitude);
NSLog(@"Longitude %f", coordinate.longitude);
}];
Apple released good documentation on forward geocoding that should help you.