测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2015年11月 |
由Fabio Caccamo维护。
iOS 地理编码器,基于 LocationManager 和 CLGeocoder,使用以块为基础的语法来执行用户当前位置的前向和反向地理编码。
它还可以用于对用户的近似位置(总是国家,几乎总是城市)进行地理编码,而不需要请求权限(使用免费 GeoIP 服务)。
FCCurrentLocationGeocoder.h
和 FCCurrentLocationGeocoder.m
复制到您的项目中从 iOS 8 开始,必须在 Info.plist
文件中添加 NSLocationWhenInUseUsageDescription
键。此键的值将作为在请求位置权限时向用户显示的 UIAlertView 的描述。有关更多信息,请参阅 Apple 文档。
基本操作就是在 Info.plist
文件中添加一个条目。添加键 NSLocationWhenInUseUsageDescription
,并选择类型 String
。为此条目输入的值将在第一次尝试确定用户的地理位置时作为文本显示在 UIAlertView 中。最后它应该看起来像这样:
//you can use the shared instance
[FCCurrentLocationGeocoder sharedGeocoder];
//you can also use as many shared instances as you need
[FCCurrentLocationGeocoder sharedGeocoderForKey:@"yourKey"];
//or create a new geocoder and set options
FCCurrentLocationGeocoder *geocoder = [FCCurrentLocationGeocoder new];
geocoder.canPromptForAuthorization = NO; //(optional, default value is YES)
geocoder.canUseIPAddressAsFallback = YES; //(optional, default value is NO. very useful if you need just the approximate user location, such as current country, without asking for permission)
geocoder.timeFilter = 30; //(cache duration, optional, default value is 5 seconds)
geocoder.timeoutErrorDelay = 10; //(optional, default value is 15 seconds)
//check if location services are enabled and the current app is authorized or could be authorized
[geocoder canGeocode]; //returns YES or NO
//current-location forward-geocoding
[geocoder geocode:^(BOOL success) {
if(success)
{
//you can access the current location using 'geocoder.location'
}
else {
//you can debug what's going wrong using: 'geocoder.error'
}
}];
//current-location reverse-geocoding
[geocoder reverseGeocode:^(BOOL success) {
if(success)
{
//you can access the current location using 'geocoder.location'
//you can access the current location placemarks using 'geocoder.locationPlacemarks'
//you can access the current location first-placemark using 'geocoder.locationPlacemark'
//you can access the current location country using 'geocoder.locationCountry'
//you can access the current location country-code using 'geocoder.locationCountryCode'
//you can access the current location city using 'geocoder.locationCity'
//you can access the current location zip-code using 'geocoder.locationZipCode'
//you can access the current location address using 'geocoder.locationAddress'
}
else {
//you can debug what's going wrong using: 'geocoder.error'
}
}];
//check if geocoding
[geocoder isGeocoding]; //returns YES or NO
//cancel geocoding
[geocoder cancelGeocode];
The MIT License (MIT)
在此协议下,任何获得此软件及其相关文档副本(“软件”)的个人均可免费使用该软件,不受限制,包括但不限于使用、复制、修改、合并、发布、分发、转让和/或销售软件的副本,并允许向软件提供的人这样做,前提是
上述版权声明和本许可协议应包含在软件的所有副本或主要部分中。
本软件按照“现状”提供,不提供任何形式的保修,无论是明示的还是默示的,包括但不限于适销性、特定用途适用性和非侵权性。在任何情况下,作者或版权所有者不应对任何主张、损害或其他责任承担责任,无论呈标本合同、侵权或其他行为,是否源自、产生于或与软件或对软件的使用或其他方式有关。