在iPhone中按名称查找位置(重复)

时间:2014-10-13 12:30:09

标签: ios objective-c iphone

我是iOS应用程序开发的新手。 所以,我想问一下如何按名称获取位置坐标。

2 个答案:

答案 0 :(得分:1)

您可以使用CLGeocoder获取位置坐标(转发地理编码)。

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

参考Link

答案 1 :(得分:1)

您想获取用户的位置并显示它,还是希望用户输入地址然后显示该地址的坐标?

获取iOS7(或更早版本)中的用户位置: http://ios-blog.co.uk/tutorials/getting-the-users-location-using-corelocation/

对于iOS8,您需要做一些小的调整: http://matthewfecher.com/app-developement/getting-gps-location-using-core-location-in-ios-8-vs-ios-7/

如果您想要地址的坐标,可以使用CLGeocoder中的此方法:

- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler

不幸的是,这在美国之外并不是很好。您可以使用其他服务,但它们会花费您一些钱。请查看此主题以获取更多信息:Get Coordinates for given Location

相关问题