我使用iOS版Google Maps API。我想获取特殊城市的静态图像并将其粘贴到UIImageView中。我该怎么做?
@Ankit的回复是正确的,但是@Alexsander在Swift中问,所以:
var staticMapUrl: String = "http://maps.google.com/maps/api/staticmap?markers=color:blue|\(self.staticData.latitude),\(self.staticData.longitude)&\("zoom=13&size=\(2 * Int(mapFrame.size.width))*\(2 * Int(mapFrame.size.height))")&sensor=true" var mapUrl: NSURL = NSURL(string: staticMapUrl.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding))! var image: UIImage = UIImage.imageWithData(NSData.dataWithContentsOfURL(mapUrl)) var mapImage: UIImageView = UIImageView(frame: mapFrame)
快速4
let staticMapUrl: String = "http://maps.google.com/maps/api/staticmap?markers=\(self.finalLatitude),\(self.finalLongitude)&\("zoom=15&size=\(2 * Int(imgViewMap.frame.size.width))x\(2 * Int(imgViewMap.frame.size.height))")&sensor=true" let mapUrl: NSURL = NSURL(string: staticMapUrl)! self.imgViewMap.sd_setImage(with: mapUrl as URL, placeholderImage: UIImage(named: "palceholder"))