iphone - MKMapView使用名称在国家/地区上放置图钉

标签 iphone objective-c ios ipad mkmapview

我有一组国家/地区名称,希望将它们作为地标放置在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/

相关文章:

iphone - 从其他 NSString 的某个点创建 NSString

objective-c - 你什么时候想在辅助线程上运行 NSURLConnection ?

ios - nil __weak self - 为什么会这样?

ios - 检测用户是否在 iTunes 商店中登录

html - Iframe pdf 滚动在 IOS 设备(iPhone、iPad)中不可见

iphone - 界面方向 iOS

iphone - 安装时将数据传递到我的应用程序

iphone - 在 iOS 5.1 中从应用程序打开 Twitter 设置

objective-c - (BOOL)窗口应该关闭 :(id)sender doesn't work in view that i set as contentview of mainmenu's window

iphone - 如何在 iOS 中从 webview 返回到 rootview?