如何在iOS中将地图区域限制为只有一个国家? [英] how can I limit the map area to only one country in iOS?

查看:493
本文介绍了如何在iOS中将地图区域限制为只有一个国家?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mapkit制作iOS应用程式。我想限制地图的边界只有一个特定的地区/国家。有没有办法做这个?

I am making an app for iOS using mapkit. I want to limit the boundaries of the map only to a specific region/country. Is there a way to do this?

推荐答案

这里是上一个答案的进一步说明。请注意,对于世界的不同部分,这将有所不同:

Here is a further specification of the previous answer. Note that this will be different for different parts of the world:

    if(neCoord.latitude > myNorthEast.latitude){
        MKCoordinateRegion newRegion;
        newRegion.span = region.span;
        CLLocationCoordinate2D newCenter;
        newCenter.longitude = region.center.longitude;
        newCenter.latitude = myNorthEast.latitude - region.span.latitudeDelta / 2;
        newRegion.center = newCenter;
        [mapView setRegion:newRegion animated:NO];

    } else if(swCoord.latitude < mySouthWest.latitude){
        MKCoordinateRegion newRegion;
        newRegion.span = region.span;
        CLLocationCoordinate2D newCenter;
        newCenter.longitude = region.center.longitude;
        newCenter.latitude = mySouthWest.latitude + region.span.latitudeDelta / 2;
        newRegion.center = newCenter;
        [mapView setRegion:newRegion animated:NO];

    } else if(neCoord.longitude > myNorthEast.longitude){
        MKCoordinateRegion newRegion;
        newRegion.span = region.span;
        CLLocationCoordinate2D newCenter;
        newCenter.longitude = myNorthEast.longitude - region.span.longitudeDelta / 2;
        newCenter.latitude = region.center.latitude;
        newRegion.center = newCenter;
        [mapView setRegion:newRegion animated:NO];

    } else if(swCoord.longitude < mySouthWest.longitude){
        MKCoordinateRegion newRegion;
        newRegion.span = region.span;
        CLLocationCoordinate2D newCenter;
        newCenter.longitude = mySouthWest.longitude + region.span.longitudeDelta / 2;
        newCenter.latitude = region.center.latitude;
        newRegion.center = newCenter;
        [mapView setRegion:newRegion animated:NO];
    }

这篇关于如何在iOS中将地图区域限制为只有一个国家?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆