Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS的MapKit中显示一个特定的国家/地区地图_Ios_Mapkit - Fatal编程技术网

在iOS的MapKit中显示一个特定的国家/地区地图

在iOS的MapKit中显示一个特定的国家/地区地图,ios,mapkit,Ios,Mapkit,是否有可能使用Swift在iOS中显示特定的国家/地区地图 我已经搜索了很多,但大多数其他答案都建议只使用缩放效果绑定地图 但我认为这对我来说不是正确的解决方案。注意以下坐标是随机的,就像示例一样 在swift代码中的某个地方,您将声明您的MKMapView @IBOutlet var-mapView:MKMapView 稍后,可能在中覆盖func viewDidLoad(), 您可以设置地图视图的区域和span var location: CLLocationCoordinate2D! var

是否有可能使用Swift在iOS中显示特定的国家/地区地图

我已经搜索了很多,但大多数其他答案都建议只使用缩放效果绑定地图


但我认为这对我来说不是正确的解决方案。

注意以下坐标是随机的,就像示例一样

在swift代码中的某个地方,您将声明您的
MKMapView

@IBOutlet var-mapView:MKMapView

稍后,可能在
中覆盖func viewDidLoad()

您可以设置地图视图的
区域和
span

var location: CLLocationCoordinate2D!
var region: MKCoordinateRegion!
var span: MKCoordinateSpan!

mapView = MKMapView() // allocating a mapview, so setting the region makes sens.

location = CLLocationCoordinate2DMake(2.0, 1.0)
span = MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2)
region = MKCoordinateRegion.init(center: location, span: span)
mapView.setRegion(region, animated: true)
请记住,地图上没有国家和边界列表可供选择,但有一些服务可以帮助您通过地址或国家名称查找位置坐标

按国家名称查找地图区域的方法之一。
对不起,在objective-c中

if (@available(iOS 13.0, *)) {
    MKPlacemark *placemark = nil;
    MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] initWithNaturalLanguageQuery:@"USA"];
    request.resultTypes = MKLocalSearchResultTypeAddress;
    MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
    [search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
        if (!error) {
            [self.mapView setRegion:response.boundingRegion];
            
            //or do something with first result..
            //if ([response mapItems].count>0) {
                // MKPlacemark *placemark = [response mapItems].firstObject.placemark;
                // MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
                // and so on..
            //}
        }
    }];
}
或迅捷

if #available(iOS 13.0, *) {
    
    let searchRequest = MKLocalSearch.Request()
    searchRequest.naturalLanguageQuery = "USA"
    
    let search = MKLocalSearch(request: searchRequest)
    
    search.start { response, error in
        guard let response = response else {
            print("Error: \(error?.localizedDescription ?? "Unknown error").")
            return
        }
        
        self.mapView.setRegion(response.boundingRegion, animated: true)
    }
}

注意,以下坐标是随机的,正如示例所示

在swift代码中的某个地方,您将声明您的
MKMapView

@IBOutlet var-mapView:MKMapView

稍后,可能在
中覆盖func viewDidLoad()

您可以设置地图视图的
区域和
span

var location: CLLocationCoordinate2D!
var region: MKCoordinateRegion!
var span: MKCoordinateSpan!

mapView = MKMapView() // allocating a mapview, so setting the region makes sens.

location = CLLocationCoordinate2DMake(2.0, 1.0)
span = MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2)
region = MKCoordinateRegion.init(center: location, span: span)
mapView.setRegion(region, animated: true)
请记住,地图上没有国家和边界列表可供选择,但有一些服务可以帮助您通过地址或国家名称查找位置坐标

按国家名称查找地图区域的方法之一。
对不起,在objective-c中

if (@available(iOS 13.0, *)) {
    MKPlacemark *placemark = nil;
    MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] initWithNaturalLanguageQuery:@"USA"];
    request.resultTypes = MKLocalSearchResultTypeAddress;
    MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];
    [search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {
        if (!error) {
            [self.mapView setRegion:response.boundingRegion];
            
            //or do something with first result..
            //if ([response mapItems].count>0) {
                // MKPlacemark *placemark = [response mapItems].firstObject.placemark;
                // MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
                // and so on..
            //}
        }
    }];
}
或迅捷

if #available(iOS 13.0, *) {
    
    let searchRequest = MKLocalSearch.Request()
    searchRequest.naturalLanguageQuery = "USA"
    
    let search = MKLocalSearch(request: searchRequest)
    
    search.start { response, error in
        guard let response = response else {
            print("Error: \(error?.localizedDescription ?? "Unknown error").")
            return
        }
        
        self.mapView.setRegion(response.boundingRegion, animated: true)
    }
}
是否有可能在iOS中显示特定的国家/地区地图

不管编程语言是什么,只有当你的应用程序有你想显示的每个国家的相关数据(中心和地区)时,这才可能实现。MapKit本身没有这样的功能

事实上,正如@OlSen的节目所示,这是可能的

是否有可能在iOS中显示特定的国家/地区地图

不管编程语言是什么,只有当你的应用程序有你想显示的每个国家的相关数据(中心和地区)时,这才可能实现。MapKit本身没有这样的功能


正如@OlSen所示,这实际上是可能的。

我同意大多数答案,因为MapKit不支持开箱即用

如果您还没有看一看,以更好地了解如何以简单的方式利用自己的数据

但是,您可以使用自己的custon形状(符合MKOverlay协议)自由注释MapKit


我同意大多数答案,因为MapKit不支持开箱即用

如果您还没有看一看,以更好地了解如何以简单的方式利用自己的数据

但是,您可以使用自己的custon形状(符合MKOverlay协议)自由注释MapKit


不是100%正确。。很抱歉感谢您的指针和示例代码!我不知道本地搜索也适用于此,很高兴知道!你的答案应该是被接受的。不是100%正确。。很抱歉感谢您的指针和示例代码!我不知道本地搜索也适用于此,很高兴知道!你的答案应该是可以接受的。如果你想知道如何从plist中放置覆盖层作为国家边界。或者您继续使用一项服务,该服务具有按国家划分的所需土地覆盖数据,就像您对如何从plist将覆盖层放置为国家边界感到好奇一样。或者你继续使用一项服务,该服务包含按国家划分的所需土地覆盖数据,如