通过在iphone中给出位置名称来获取坐标

| 是否可以通过在iPhone中给出地点的名称来获取坐标?我不想使用任何Web服务,因为它们没有什么限制。我可以使用iPhone SDK吗? 提前致谢。     
已邀请:
正如@ raj2raaz提到的那样,我们仅通过指定地点的名称就无法获取坐标,必须在iPhone中使用网络服务才能获取坐标。 http://iphonesdksnippets.com/post/2010/02/15/Get-Coordinates-from-Address.aspx     
简短的回答是“否”,您无法给出地址并获得经度/纬度位置。几个人编写了使用不同Web服务的库,有关详细信息,请参见此答案:从iPhone转发地理编码。 我知道您说过您不想使用各种Web服务,但是,您不能免费获得所有内容。有人的CPU周期将不得不进行搜索。在我看来,其中大多数似乎具有大多数应用可接受的术语。     
是的,有可能,但是您必须做一些工作。我目前正在将这项工作放在我的一个项目中。 GeoNames地理数据库覆盖所有国家,并且包含超过800万个地名,可以免费下载。我正在将他们的人口超过1000 3.9M zip文件的引用添加到我的项目中。它包含每个城市的经度/纬度。我将把每个城市解析成一个自定义的NSObject并将它们加载到Core Data中。 在我的项目中,我不会查找城市名称,而是要查找到特定纬度/经度坐标的壁橱城市。 Haversine公式用于计算球面上两个点之间的距离。这是用Objective-C和Perl编写的公式。 我当前解析该数据的进度可以在这里找到。我还有工作要完成。     
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:YOUR_LOCATION completionHandler:^(NSArray* placemarks, NSError* error)     
{
    NSLog(@\"completed\");
    if ( error )
    {
        NSLog(@\"error = %@\", error );
    }
    else
    {
        //Here you get information about the place in placemarks array
    }
}];
    
您可以通过调用此方法来获取坐标。此方法需要地址(地点名称)。
-(CLLocationCoordinate2D) addressLocation:(NSString *)addrss {
    NSString *urlString = [NSString stringWithFormat:@\"http://maps.google.com/maps/geo?q=%@&output=csv\", 
                           [addrss stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSArray *listItems = [locationString componentsSeparatedByString:@\",\"];

double latitude = 0.0;
double longitude = 0.0;

if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@\"200\"]) {
    latitude = [[listItems objectAtIndex:2] doubleValue];
    longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
    //Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;

return location;
}     

要回复问题请先登录注册