如何从地址确定CLLocation或MKPlacemark? [英] How can I determine a CLLocation or MKPlacemark from an address?
本文介绍了如何从地址确定CLLocation或MKPlacemark?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看过API文档和演示后的演示,它们演示了如何进行反向地址解析-在指定纬度/经度位置的情况下获取地址.我需要做相反的事情.我假设这已经解决了问题,因为Apple的MapKit API完全避免了它.
I've seen API documentation and demo after demo on how to do a reverse geocode - to get an address, given a Lat/Long location. I need to do the reverse. I'm assuming that this is already solved problem since Apple's MapKit API avoids it entirely.
推荐答案
一种方法是像这样使用google网络服务:
One way is to use the google webservice like so:
-(CLLocationCoordinate2D) addressLocation {
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSLog(@"locationString = %@",locationString);
NSArray *listItems = [locationString componentsSeparatedByString:@","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
/*
NSString *nameString = [NSString stringWithFormat:@"http://ws.geonames.org/findNearestAddress?lat=%f&lng=%f",latitude,longitude];
NSString *placeName = [NSString stringWithContentsOfURL:[NSURL URLWithString:nameString]];
NSLog(@"placeName = %@",placeName);
*/
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
这篇关于如何从地址确定CLLocation或MKPlacemark?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文