@IBOutlet weak var getout: UIButton!
@IBOutlet weak var legstreet: UIImageView!
@IBOutlet weak var viewStreett: GMSPanoramaView!
var panoramaNear: CLLocationCoordinate2D!
override func viewDidLoad() {
super.viewDidLoad()
panoramaNear = CLLocationCoordinate2DMake(30.274262, -97.752371)
//var panoramaNear = self.tmpString
var panoView = GMSPanoramaView.panoramaWithFrame(CGRectZero,
nearCoordinate:panoramaNear)
self.viewStreett = panoView
// Do any additional setup after loading the view.
}
When I write like this, the street view can't show. and I have to revise
self.viewStreett = panoView
to self.view = panoView.
But at this time UIImageView disappear. So my question is how to add UIImageView into streetview and don't disturb the use of street view.
Your viewStreet
will be a loading GMSPanoramaView
, because it has no coordinate. So you can not make a loading GMSPanoramaView
equals to your panoView
(viewStreet = panoView
wont work).
Instead, you can change the type of viewStreet
to UIView
, now it will behavior like a container view of your panoView
. Then you can do viewStreet.addSubview(panoView)
to add your panoView
to the container.
Sample Code:
@IBOutlet weak var viewStreet: UIView!
@IBOutlet weak var sampleImageView: UIImageView!
var panoView: GMSPanoramaView!
override func viewDidLoad() {
super.viewDidLoad()
let panoramaNear = CLLocationCoordinate2DMake(30.274262, -97.752371)
panoView = GMSPanoramaView.panoramaWithFrame(CGRectZero,
nearCoordinate:panoramaNear)
viewStreet.addSubview(panoView)
viewStreet.sendSubviewToBack(panoView)
let equalWidth = NSLayoutConstraint(item: panoView, attribute: .Width, relatedBy: .Equal, toItem: viewStreet, attribute: .Width, multiplier: 1.0, constant: 0)
let equalHeight = NSLayoutConstraint(item: panoView, attribute: .Height, relatedBy: .Equal, toItem: viewStreet, attribute: .Height, multiplier: 1.0, constant: 0)
let top = NSLayoutConstraint(item: panoView, attribute: .Top, relatedBy: .Equal, toItem: viewStreet, attribute: .Top, multiplier: 1.0, constant: 0)
let left = NSLayoutConstraint(item: panoView, attribute: .Left, relatedBy: .Equal, toItem: viewStreet, attribute: .Left, multiplier: 1.0, constant: 0)
panoView.setTranslatesAutoresizingMaskIntoConstraints(false)
NSLayoutConstraint.activateConstraints([equalWidth, equalHeight, top, left])
}
If you are using AutoLayout in your app, you should add width, height, top and left constraints to your panoView
.
You can view sample app in this GitHub page.
In the simulator screenshot below, I simply add a marker image on top of the panoView
.