I want to get the location name from the coordinate value. Here is code,
- (void)viewWillAppear:(BOOL)animated { CLLocationCoordinate2D zoomLocation; zoomLocation.latitude = 39.281516; zoomLocation.longitude= -76.580806; MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE); MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion]; [_mapView setRegion:adjustedRegion animated:YES]; }
So, From that Latitude and longitude , i want to know that location name.
You can input and search maps by GPS coordinates on the iPhone easily by using the Apple Maps or Google Maps applications, as we'll demonstrate in this walkthrough.
Open the Maps app. Tap Search at the bottom of the screen. Enter the latitude and longitude coordinates in the search bar. Coordinates can be in decimal degree format or degrees, minutes, seconds.
The Below code shall work in ios5 and above
CLGeocoder *ceo = [[CLGeocoder alloc]init]; CLLocation *loc = [[CLLocation alloc]initWithLatitude:32.00 longitude:21.322]; //insert your coordinates [ceo reverseGeocodeLocation:loc completionHandler:^(NSArray *placemarks, NSError *error) { CLPlacemark *placemark = [placemarks objectAtIndex:0]; if (placemark) { NSLog(@"placemark %@",placemark); //String to hold address NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "]; NSLog(@"addressDictionary %@", placemark.addressDictionary); NSLog(@"placemark %@",placemark.region); NSLog(@"placemark %@",placemark.country); // Give Country Name NSLog(@"placemark %@",placemark.locality); // Extract the city name NSLog(@"location %@",placemark.name); NSLog(@"location %@",placemark.ocean); NSLog(@"location %@",placemark.postalCode); NSLog(@"location %@",placemark.subLocality); NSLog(@"location %@",placemark.location); //Print the location to console NSLog(@"I am currently at %@",locatedAt); } else { NSLog(@"Could not locate"); } } ];
-(NSString *)getAddressFromLatLon:(double)pdblLatitude withLongitude:(double)pdblLongitude { NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=csv",pdblLatitude, pdblLongitude]; NSError* error; NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error]; // NSLog(@"%@",locationString); locationString = [locationString stringByReplacingOccurrencesOfString:@"\"" withString:@""]; return [locationString substringFromIndex:6]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With