Ios 当你有经度和纬度时,如何找到用户的位置?

Ios 当你有经度和纬度时,如何找到用户的位置?,ios,Ios,我想从给定的纬度和经度中找到位置。问题是,在我的应用程序中,我必须一次找到20多个用户位置,并且长时间的lat数据来自服务,我的任务是从经度和纬度获取位置…在此url中传递您的经度和纬度值 NSString *urlString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true",coordinate.latitude,c

我想从给定的纬度和经度中找到位置。问题是,在我的应用程序中,我必须一次找到20多个用户位置,并且长时间的lat数据来自服务,我的任务是从经度和纬度获取位置…

在此url中传递您的经度和纬度值

    NSString *urlString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=true",coordinate.latitude,coordinate.longitude];
    NSURL *url = [NSURL URLWithString:urlString];

    NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:nil error:nil];
    annotation.tag = 0;
    //SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    if([[dict valueForKey:@"results"] count]>0)
        NSString *location = [[[dict valueForKey:@"results"] objectAtIndex:0] valueForKey:@"formatted_address"];

使用iOS的反向地理编码。有一个
CLGeocoder
类来自Mapkit Framework,它使用
reverseGeocodeLocation
方法从纬度和经度检索用户的实际位置

- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler
此方法采用两个参数:

location:使用纬度和经度创建
CLLocation
对象,并将该对象传递给此方法。 这就是创建
CLLocation
对象的方法

 CLLocation *location = [[CLLocation alloc]initWithLatitude:_yourLatitude longitude:_yourLongitude];
completionHandler:这是一个在反向地理编码成功时执行的块对象

你可以看看这个

将值传递给此reverseGeocodeLocation处理程序。

您应该先了解流程。这就是所谓的地理编码。 您有两种地理编码,正向和反向地理编码。您可以从经纬度获取地址,也可以从地址获取经纬度。 你应该学习一些教程。这里有一些链接

您还可以使用谷歌API进行地理编码,这将提供最佳结果

干杯
Sanjay

CLLocation*newLocation=[[CLLocation alloc]initWithLatitude:纬度经度:经度];为什么反向地理编码器与gogle Api相比能给出准确的位置?我不认为总是这样。有时结果并不那么准确。需要了解的是,CLGeocoder对象也使用Internet/或Web服务来获取信息。Thanx…适合我
    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {

    }];