我有一组国家/地区名称,希望将它们作为地标放置在MKMapView上。因此,例如,如果法国在countryName数组中,我希望在法国中心放置一个图钉。
有没有办法在不为每个国家/地区存储经/纬度的情况下进行此操作?
我想使这项工作脱机,并且只需要其最基本且完全缩小的世界图像即可。
我相信MKMapView拥有一些基本的地理信息,因此在不使用GLGeocoder和互联网连接的情况下,上述方法是否可行?
最佳答案
尝试使用此功能获取地址的经度和纬度:-(如果您仅使用国家/地区名称,则该国家/地区的经纬度会很长)
-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) countryStr {
NSString *urlAddressStr = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[countryStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlAddressStr]];
NSArray *items = [locationStr componentsSeparatedByString:@","];
double lat = 0.0;
double long = 0.0;
if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"])
{
lat = [[items objectAtIndex:2] doubleValue];
long = [[items objectAtIndex:3] doubleValue];
}
CLLocationCoordinate2D location;
location.latitude = lat;
location.longitude = long;
return location;
}
在获得经度和纬度之后
1)添加使用mapKit框架
3)在区域上设置纬度和经度
3)使用此功能
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
关于iphone - MKMapView使用名称在国家/地区上放置图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9902957/