Get latitude and longitude based on zip using Geocoder class in IOS

前端 未结 3 2097
温柔的废话
温柔的废话 2020-12-16 05:24

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

3条回答
  •  长情又很酷
    2020-12-16 05:47

    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);
        }];
    

提交回复
热议问题