ios7 或更高
TIMapboxGeocoder 可以通过 CocoaPods 获得。要安装它,只需在 Podfile 中添加以下行
pod "TIMapboxGeocoder"
首先,导入此库
#import "TIMapboxGeocoder.h"
TIMapboxGeocoder* geocoder = [[TIMapboxGeocoder alloc] initWithAccessToken:@"XXXX-XXXXX-XXXXX"];
您需要一个 Mapbox 访问令牌
TIMapboxGeocoder* geocoder = [[TIMapboxGeocoder alloc] initWithAccessToken:@"XXXX-XXXXX-XXXXX"];
[geocoder geocodeAddressString:@"Paris" proximity:nil completionHandler:^(NSArray *results, NSError *error) {
if (error) {
// Handle error
}
TIPlacemark* placemark = results.firstObject;
NSLog(@"First placemark name : %@", placemark.name);
}];
Nb : proximity 可以是 nil 或靠近搜索区域的 CLLocation
对象
CLLocation* location = [[CLLocation alloc] initWithLatitude:0.0 longitude:0.0];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *results, NSError *error) {
if (error) {
// Handle error
}
TIPlacemark* placemark = results.firstObject;
NSLog(@"First placemark name : %@", placemark.name);
}];
@interface TIPlacemark : NSObject
- (CLLocation*) location;
- (NSString*) name;
@end
Benjamin Digeon,TingsLabs (http://www.tingslabs.com),[email protected]
此 Objective-C 实现受到原始 MapBox 地理编码实现灵感的启发。
在此处查看原始 Swift 实现: https://github.com/mapbox/MapboxGeocoder.swift
TIMapboxGeocoder 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。