我想自动填写用户的地址,与google api在此链接中提供的地址相同:
https://developers.google.com/maps/documentation/javascript/places-autocomplete?hl=en
如何使用Apple地图套件实现相同的功能?
我试过使用Geo Coder,我写了这个例子:
@IBAction func SubmitGeoCode(sender: AnyObject) {
let address = "1 Mart"
let coder = CLGeocoder()
coder.geocodeAddressString(address) { (placemarks, error) -> Void in
for placemark in placemarks! {
let lines = placemark.addressDictionary?["FormattedAddressLines"] as? [String]
for addressline in lines! {
print(addressline)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然而,结果非常令人失望.
任何可用于实现此类功能的Apple API,或者我应该使用google api?
谢谢
我有一个应用程序,它进行前向地理编码(获取给定地址的坐标)以显示一堆引脚MKMapView.该应用程序是在iOS支持前向地理编码之前开发的CLGeocoder(首先在iOS 5中提供).因此,我的应用程序使用Google Maps Geocoding API,这通常非常准确.给定一个带有街道号码的完整地址,它通常会在几米内为您提供该地址的确切位置.
我正在对我的应用程序进行一些更新以支持iOS 6,并决定从使用Google API切换到使用,CLGeocoder只要该应用程序在iOS 5或更高版本上运行.然而,在我的测试中(所有地址都在葡萄牙,我居住的地方),它是如此不准确,以至于完全无法使用.
我使用的– geocodeAddressString:completionHandler:,例如,给出的地址"自由大道195,里斯本,葡萄牙"它给了我一个"自由大道"在城市辛特拉,不葡京(里斯本)的.距离真实地址约15公里.Avenida da Liberdade是里斯本最大和最着名的大道之一.相当于纽约市的第五大道.这不是一些不起眼的小街道.
有没有什么我做错了得到如此可怕的准确性?其他人是否有类似的准确性问题,特别是在美国以外的地址?
目前看来我必须坚持使用Google Maps API.顺便说一句,我一直在使用iOS 6模拟器,结果并没有更好.将相同的搜索字符串放入iOS 6地图应用程序的搜索框中会产生完全不准确的结果.
编辑:添加CLGeocoder代码:
CLGeocoder *fgeo = [[[CLGeocoder alloc] init] autorelease];
NSLog(@"Geocoding for Address: %@\n", address);
[fgeo geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
if (!error) {
// do stuff with the placemarks
for (CLPlacemark *placemark in placemarks) {
NSLog(@"%@\n %.2f,%.2f",[placemark description], placemark.location.horizontalAccuracy, placemark.location.verticalAccuracy);
}
} else {
NSLog(@"Geocoding error: %@", [error …Run Code Online (Sandbox Code Playgroud)