首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从mapView获取视口坐标吗?regionDidChanged迅捷

从mapView获取视口坐标吗?regionDidChanged迅捷
EN

Stack Overflow用户
提问于 2016-04-07 12:26:32
回答 1查看 3.1K关注 0票数 5

当用户移动地图时,将调用以下函数。

有可能获得视口吗?视口是北纬、东经和拉特。还有。南部/西部的。

代码语言:javascript
运行
复制
 func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool){
    print("The \(mapView.centerCoordinate)")
    print("the maprect \(mapView.visibleMapRect.origin)")
    print("the maprect \(mapView.visibleMapRect.size)")
    //I find just this attributes for mapView

    }

我不知道如何从我的数据中提取视图。我在网上找不到任何东西。

目的是用google分析和另一个工具来记录坐标,评估数据。

有人有主意吗?非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-07 12:47:50

MapKit

代码语言:javascript
运行
复制
let northEast = mapView.convertPoint(CGPoint(x: mapView.bounds.width, y: 0), toCoordinateFromView: mapView)
let southWest = mapView.convertPoint(CGPoint(x: 0, y: mapView.bounds.height), toCoordinateFromView: mapView)

googleMaps

mapView有一个属性“投影”,可以使用"coordinateForPoint“将点从mapView转换为坐标。因此,以下几点可以发挥作用:

谷歌地图maps 3

代码语言:javascript
运行
复制
let northEast = mapView.projection.coordinate(for: CGPoint(x: mapView.layer.frame.width, y: 0))
let southWest = mapView.projection.coordinate(for: CGPoint(x: 0, y: mapView.layer.frame.height))

swift 2

代码语言:javascript
运行
复制
let northEast = mapView.projection.coordinateForPoint(CGPoint(x: mapWidth, y: 0 ))
let southWest = mapView.projection.coordinateForPoint(CGPoint(x: 0, y: mapHeight))

你只需要输入你的mapView宽度和高度

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36476163

复制
相关文章

相似问题

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