如何从swift 3中的iOS谷歌地图获取静态图像

时间:2016-11-16 18:01:12

标签: ios swift google-maps

我使用谷歌地图api for iOS。我想得到地图的静态图像,我有纬度和经度,并希望将其粘贴到UIImageView中。如何在swift 3.0中制作它?

2 个答案:

答案 0 :(得分:1)

你可以试试:

myMap.snapshotView(afterScreenUpdates: true)

它将返回一个你可以随意使用的UIView

答案 1 :(得分:-1)

Swift 3 =>
        let Width = 100
        let Height = 200

        let mapImageUrl = "https://maps.googleapis.com/maps/api/staticmap?center="
        let latlong = "18.495651759752, 73.809987567365"

        let mapUrl  = mapImageUrl + latlong

        let size = "&size=" +  "\(Int(Width))" + "x" +  "\(Int(Height))"
        let positionOnMap = "&markers=size:mid|color:red|" + latlong
        let staticImageUrl = mapUrl + size + positionOnMap

        if let urlStr : NSString = staticImageUrl.addingPercentEscapes(using:String.Encoding.utf8)! as NSString{
            // setImageFromURL 
       }