Tag Archives: 算法技巧

如何解决百度地图反地理编码失败的问题!!

我们在使用百度地图定位成功后,一般会使用反地理编码的方式进行地址解析,获取地址信息供我们应用使用,如下方法所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 获取地址位置后调用方法
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
/*
????code for location...
?*/
????????// 反地址编码获取地址
????????BMKReverseGeoCodeOption *option = [[BMKReverseGeoCodeOption alloc] init];
????????option.reverseGeoPoint = userLocation.location.coordinate;
?????????
????????SALog(@"开始反地理编码...");
?????????
????????if (![self.geoCode reverseGeoCode:option]){
????????????SALog(@"反地址编码失败,使用Apple地图反地理编码");
????????????CLLocationCoordinate2D newCoor = [[self class] GCJ02FromBD09:userLocation.location.coordinate];
????????????CLLocation *location = [[CLLocation alloc] initWithLatitude:newCoor.latitude longitude:newCoor.longitude];
????????????[[[CLGeocoder alloc] init] reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
????????????????CLPlacemark *placemark = [placemarks firstObject];
????????????????SALog(@"%@ - %@", placemark.name, placemark.locality);
/*
????code for address...
?*/
????????????}];
????????}
????????// 结束
????}
}

[……]

继续阅读

iOS制作自定义数字键盘

一、应用场景

很多情况下我们的输入都是有硬性要求的,比如只能输入数字,通常情况下我们的解决方案就是指定输入框的键盘模式(keyboardType),可系统提供给我的键盘种类还是非常有限的,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
typedef NS_ENUM(NSInteger, UIKeyboardType) {
????UIKeyboardTypeDefault,??????????????? // Default type for the current input method.
????UIKeyboardTypeASCIICapable,?????????? // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
????UIKeyboardTypeNumbersAndPunctuation,? // Numbers and assorted punctuation.
????UIKeyboardTypeURL,??????????????????? // A type optimized for URL entry (shows . / .com prominently).
????UIKeyboardTypeNumberPad,????????????? // A number pad (0-9). Suitable for PIN entry.
????UIKeyboardTypePhonePad,?????????????? // A phone pad (1-9, *, 0, #, with letters under the numbers).
????UIKeyboardTypeNamePhonePad,?????????? // A type optimized for entering a person's name or phone number.
????UIKeyboardTypeEmailAddress,?????????? // A type optimized for multiple email address entry (shows space @ . prominently).
????UIKeyboardTypeDecimalPad NS_ENUM_AVAILABLE_IOS(4_1),?? // A number pad with a decimal point.
????UIKeyboardTypeTwitter NS_ENUM_AVAILABLE_IOS(5_0),????? // A type optimized for twitter text entry (easy access to @ #)
????UIKeyboardTypeWebSearch NS_ENUM_AVAILABLE_IOS(7_0),??? // A default keyboard type with URL-oriented addition (shows space . prominently).
?
????UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
?
};

[……]

继续阅读

使用AVFoundation自定义相机如何调整相机焦距

1、如何使用AVFoundation框架自定义相机请先参照iOS项目实战之自定义相机

2.1、上述帖子中有讲到,如果需要对焦,可以通过AVCaptureDevicesetFocusPointOfInterest:方法来实现,传入一个CGPoint值,但这里的CGPoint不是View上面的点,而是范围的0~1的相对百分点;

2.2、这个CGPoint如何得来呢,我们在点击屏幕时可以监听相关View的点击事件,添加一个UITapGestureRecognizer手势,在点时后,可以通过UITapGestureRecognizerlocationInView:方法得到CGPoint,这是一个绝对值,即点击了相关View上的某个点,有了这个点,再通过AVCaptureVideoPreviewLayer的一个转换方法:captureDevicePointOfInterestForPoint:可以将绝对点转换成相对点。[……]

继续阅读