【发布时间】:2014-10-13 12:30:08
【问题描述】:
我是 iOS 应用程序开发的新手。 所以,我想问一下如何通过名称获取位置坐标。
【问题讨论】:
-
Thanks.but 有一些错误理解我在问用户可以给出位置名称并想要纬度和经度。
-
这个问题看起来很基本。
标签: ios objective-c iphone
我是 iOS 应用程序开发的新手。 所以,我想问一下如何通过名称获取位置坐标。
【问题讨论】:
标签: ios objective-c iphone
您可以使用CLGeocoder 获取位置坐标(Forward geoCoding)。
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
【讨论】:
您想获取用户位置并显示它还是希望用户输入地址然后显示该地址的坐标?
在 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
【讨论】: