どのように私はアドレスからCLLocationまたはMKPlacemarkを決定することができますか?
-
12-09-2019 - |
質問
緯度/経度の位置指定されたアドレスを、取得するために -
私は逆ジオコードを行う方法についてのデモの後にAPIドキュメントとデモを見てきました。私は逆を行う必要があります。私はAppleのMapKit APIは完全にそれを回避するので、これはすでに問題を解決していると仮定しています。
解決
一つの方法は、そのようにGoogleのWebサービスを使用することです
-(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;
}
所属していません StackOverflow