首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Swift游乐场中使用MapKit显示地图以快速查看?

在Swift游乐场中使用MapKit显示地图以快速查看?
EN

Stack Overflow用户
提问于 2014-06-09 14:32:27
回答 3查看 9.6K关注 0票数 24

很高兴看到swift-playground的标签-很高兴看到这种情况继续下去。

我一直在摆弄Swift,我想知道MapKit是否可以在操场上使用,这样你就可以使用Quick Look功能,这样我就可以迭代并预览我的作品。我还没有弄清楚语法,所以我想问问是否有人在游乐场环境中探索过这一点。我在想,我需要一些代码来将它建立为视图控制器。

代码语言:javascript
复制
import UIKit
import MapKit

// Sample UIView code which works great in the playground.
//var myView:UIView = UIView();
//myView.frame = CGRectMake(0, 0, 320, 560)
//myView.backgroundColor = UIColor.blueColor()

// Non working map code - no errors but can't figure out what to call or initiate to get the view in the Quick Look side.

var mapView = MKMapView();
mapView.region.center.latitude = mapView.userLocation.coordinate.latitude;
mapView.region.center.longitude = mapView.userLocation.coordinate.longitude;
mapView.region.span.latitudeDelta = 0.00725;
mapView.region.span.longitudeDelta = 0.00725;

我想我只是遗漏了一些简单的东西,让mapView自己初始化等等。我喜欢用于修补的解释游乐场区域,只需要弄清楚它是否可以实现mao功能,而不是仅仅在Xcode中编写.swift文件和环境并变得更加正式。

EN

回答 3

Stack Overflow用户

发布于 2015-11-13 14:41:15

对于OS X上的XCode7.1和Swift2.1,我打开了时间线并执行了以下操作:

代码语言:javascript
复制
import MapKit
import XCPlayground

let delta = 5.0
let frame = CGRect( x:0, y:0, width:200, height:200 )
let mapView = MKMapView( frame: frame )
var region = MKCoordinateRegion()
region.center.latitude = 31.0
region.center.longitude = -110.0
region.span.latitudeDelta = delta
region.span.longitudeDelta = delta
mapView.setRegion( region, animated: true )

XCPlaygroundPage.currentPage.liveView = mapView
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

Xcode 9.x,Swift 4.1更新:

导入PlaygroundSupport导入MapKit

代码语言:javascript
复制
let delta = 5.0
let frame = CGRect( x:0, y:0, width:200, height:200 )
let mapView = MKMapView( frame: frame )
var region = MKCoordinateRegion()
region.center.latitude = 31.0
region.center.longitude = -110.0
region.span.latitudeDelta = delta
region.span.longitudeDelta = delta
mapView.setRegion( region, animated: true )

PlaygroundPage.current.liveView = mapView
PlaygroundPage.current.needsIndefiniteExecution = true
票数 8
EN

Stack Overflow用户

发布于 2015-02-12 17:49:51

试试这个:

代码语言:javascript
复制
import UIKit
import MapKit
import XCPlayground // Required for XCPShowView

let frame = CGRect(x: 0, y: 0, width: 150, height: 150)
let mapView = MKMapView(frame: frame)
mapView.region.center.latitude = 37.3347606
mapView.region.center.longitude = -122.0548883
mapView.region.span.latitudeDelta = 0.00725
mapView.region.span.longitudeDelta = 0.00725

XCPShowView("mapview", mapView)
票数 4
EN

Stack Overflow用户

发布于 2017-06-23 08:48:17

我在Swift游乐场应用程序中尝试了一下,我只做了一些修改,并添加了一行代码。我的swift游乐场应用使用的是Swift 3.1。我希望我可以上传一段视频,在这个地图视图中,我可以放大和缩小,还可以在地图中移动。https://i.stack.imgur.com/XVqPg.jpg

代码语言:javascript
复制
import UIKit
import PlaygroundSupport
import MapKit 


var myView:UIView = UIView()
myView.frame = CGRect(origin: CGPoint (), size: CGSize(width: 320, height: 568))


var mapView = MKMapView();
mapView.region.center.latitude = 
mapView.userLocation.coordinate.latitude
mapView.region.center.longitude = 
mapView.userLocation.coordinate.longitude
mapView.region.span.latitudeDelta = 0.00725
mapView.region.span.longitudeDelta = 0.00725

myview.addSubview(mapView)


PlaygroundPage.current.liveView = mapView
PlaygroundPage.current.needsIndefiniteExecution = true
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24114823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档