Google maps into a small rectangle - ios

I'm just starting to look into learning swift and iOS app making. I'm trying to make an app that will use google maps. So far looking at examples I created a map and set
let camera = GMSCameraPosition.cameraWithLatitude(45.489434, longitude: -73.775858, zoom: 15)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
view = mapView
This works fine but covers up the entire screen, I would like to be able to set the map to the lower portion of the screen only for example so I can add other things to the top.
To do so I tried adding a view to my view controller that covers a smaller portion of the screen. This new view is a child of the main view that was already there. I then changed the class of this new smaller view to GMSMapView and linked it to viewController.swift which created this.
#IBOutlet weak var smallMap: GMSMapView!
I then assign my map to this smallMap view and my code now looks like this.
#IBOutlet weak var smallMapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
GMSServices.provideAPIKey("AIzaSyCNG-Qg6vtIL7pQ26go1hPy9mmhfEre5IU")
let camera = GMSCameraPosition.cameraWithLatitude(45.489434, longitude: -73.775858, zoom: 15)
smallMapView.camera = camera}
Is that the right thing to do to get a smaller map view? When I run this I get libc++abi.dylib: terminating with uncaught exception of type NSException error.
Anybody can help with what I'm missing?
EDIT: Here's what my Xcode view looks like
Thanks!

Related

iOS Google Maps API - Views do not Overlay Over the Map in swift

I want to add another view below the Map but the view disappear at run time.
at run time typeView disappears because of googlemap
edit
Create storyboard connection the views,
#IBOutlet weak var mapView: GMSMapView!
#IBOutlet weak var typeView: UIView!
Now, you can solve the issue by two ways,
One way:
self.mapView.sendSubview(toBack: self.typeView)
The Second Way:
self.view.bringSubview(toFront: self.typeView)
From what you asked, I understand that you want Type view to be shown over the Google Map. If so, then
Simply create an IBOutlet of the Type view as:
#IBOutlet weak var typeView: UIView!
Use the below code to bring the typeView on the front:
self.bringSubview(toFront: self.typeView)
(I am assuming that this code is to go in View)

is there a way of scrolling the mkmapview in swift automatically?

In my Storyboard in Swift app I have a UIViewController with MKMapView stretched to each edge of the screen. It was enough for me to import a MapKit, then I set up the delegate:
class MyClass: MKMapViewDelegate {
#IBOutlet weak var mapView: MKMapView!
override func viewDidLoad(){
super.viewDidLoad()
mapView.delegate = self
}
}
and then, when I ran the app, I saw the map nicely centered above my country.
I want to implement a feature, that works like this:
when user opens this view, he sees the map, but centered on a place next to my home country, then the map could scroll automatically to center to my home country. Is that even achievable?
For example, if I lived in the US and opened the map, I would see the Pacific Ocean and then the map would scroll to show me the US territory.
Of course it's possible. MKMapView has the method setRegion(_:animated:).
You could set the map region to a spot in the pacific, wait a few seconds (using a timer or dispatch_after) and then call setRegion(_:animated:) to move the map to be centered over your current location.

Creating a floating menu in an iOS application

Looking to create a floating menu in Swift for an iOS application I am developing. Something along the lines of the little red circle menu as shown in the following image.
My initial thoughts were to extend the UIViewController class and add the respective drawing/logic there, however, the application is comprised of a few other controllers, more specifically the UITableViewController which in itself extends UIViewController. Is there perhaps a good place for an extension perhaps? Or is there a more eloquent way of drawing the menu on specific views without the mass duplication of menu related code?
The menu itself will be shown on most screens, so I need to selectively enable it. It'll also be somewhat contextual based on the view/screen the user is currently on.
Any awesome ideas?
You can create your own with the animations and all the things, or you can check this library
https://github.com/lourenco-marinho/ActionButton
var actionButton: ActionButton!
override func viewDidLoad() {
super.viewDidLoad()
let twitterImage = UIImage(named: "twitter_icon.png")!
let plusImage = UIImage(named: "googleplus_icon.png")!
let twitter = ActionButtonItem(title: "Twitter", image: twitterImage)
twitter.action = { item in println("Twitter...") }
let google = ActionButtonItem(title: "Google Plus", image: plusImage)
google.action = { item in println("Google Plus...") }
actionButton = ActionButton(attachedToView: self.view, items: [twitter, google])
actionButton.action = { button in button.toggleMenu() }
}
There is another alternative with this great library :
https://github.com/yoavlt/LiquidFloatingActionButton
You just have to implement the delegate and the dataSource in your ViewController:
let floatingActionButton = LiquidFloatingActionButton(frame: floatingFrame)
floatingActionButton.dataSource = self
floatingActionButton.delegate = self
You could use view controller containment. The menu can be its own view controller with its view laid transparently over top the content view controller.
For example this can be set up in the storyboard by dragging out two container views into a vanilla view controller.

Navbar buttons not showing up in PFQueryTableViewController (parse + iOS)

I created a storyboard and added the navbar buttons I want to be displayed
But when I simulate my app, this is what I get
I have also tried to programatically add the button using navigationItem.setRightBarButtonItem(), but that doesn't show up either.
However, when I try the same thing using a normal UIViewController, it works
So my question is if this is the behavior of PFQueryTableViewController, and if so, what do I need to do to correct it?
If more details are needed, I'd be happy to provide them - just curious if anyone has run into this problem before.
EDIT
I now have the button showing up on a basic UIViewController using suggestion of #Haidous, but I can't get my PFQueryTableViewController to show up inside it. Here's what I have:
#IBOutlet weak var containerV: UIView!
var favoriteVC:FavoritesViewController = FavoritesViewController(className: "Cat")
override func viewDidLoad() {
super.viewDidLoad()
//?what goes here?
containerV = favoriteVC.view
// Do any additional setup after loading the view.
}
I'm not sure how to make it show up
******EDIT WITH SOLUTION******
I was able to simply create a container in my storyboard and add my view controller like this (in case anyone else runs into the same problem and stumbles on this question)
class WrapperFavoritesViewControllerContainerViewController: UIViewController {
#IBOutlet weak var containerV: UIView!
var favoriteVC:FavoritesViewController = FavoritesViewController(className: "Cat")
override func viewDidLoad() {
super.viewDidLoad()
addChildViewController(favoriteVC)
self.containerV.addSubview(favoriteVC.tableView)
favoriteVC.didMoveToParentViewController(self)
}
I do not know if it is because of the PFQueryTableViewController or not.. but a workaround I found was creating a normal View Controller and setting up your Nav Bar there then placing a container view and connecting it to the PFQueryTableViewController thus PFQueryTableViewController becomes the Child View Controller. Hope I helped :)

How to get Google Street View working inside a view in iPhone?

I have just recently started learning Swift and iOS development and I am trying to get Google Street View working on a Single View Application. So basically I was thinking to have a ViewController that has a view and inside the view I will have the StreetView view and a Button.
Following Google's tutorial: https://developers.google.com/maps/documentation/ios/streetview I can get everything working. It works when I do this:
self.view = panoView
Now, I am trying to achieve what I mentioned above with the following code:
class ViewController: UIViewController, GMSPanoramaViewDelegate{
#IBOutlet weak var panoramaView: GMSPanoramaView!
override func viewDidLoad() {
super.viewDidLoad()
var panoView = GMSPanoramaView(frame: CGRectZero)
self.panoramaView.addSubview(panoView)
self.panoramaView = panoView
self.panoramaView.delegate = self
panoView.moveNearCoordinate(CLLocationCoordinate2DMake(position.latitude, position.longitude))
}
}
And what I have in the storyboard is the following:
The only thing I can see is the refresh button.
I have also tried not setting the view as a GMSPanoramaView but only as a UIView, but that also didnt work
Can anyone point me to the right direction, please? Ultimately what I want is the StreetView covering all my screen and I want some buttons and some views on top of it.
I am using Xcode 6.1
Thanks
EDIT:
I added the function and can see the ID being printed out
func panoramaView(view: GMSPanoramaView!, didMoveToPanorama panorama: GMSPanorama!) {
println(panorama.panoramaID)
}
StreetView still empty

Resources