Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to get the Location name from the Coordinate value in MapKit for iPhone

Tags:

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.

like image 861
Apple Avatar asked Sep 26 '12 10:09

Apple


People also ask

Can iPhone use GPS coordinates?

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.

How do I use latitude and longitude in Apple Maps?

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.


2 Answers

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");               }           }  ]; 
like image 107
AppleDelegate Avatar answered Oct 08 '22 07:10

AppleDelegate


-(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]; } 
like image 40
Apple Avatar answered Oct 08 '22 09:10

Apple