Reputation: 1171
I am very new to both iOS developing and using the google maps sdk. I am using Xcode for my current project. I have added my API keys in the appropriate place.
So far I have this:
import UIKit import GoogleMaps import GooglePlaces
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func loadView() {
let camera = GMSCameraPosition.cameraWithLatitude(36.2108, longitude: -81.6774, zoom: 15.0)
let mapView = GMSMapView.mapWithFrame(.zero, camera: camera)
mapView.myLocationEnabled = true
if let mylocation = mapView.myLocation {
print("User's location: \(mylocation)")
} else {
print("User's location is unknown")
}
self.view = mapView
mapView.mapType = kGMSTypeTerrain
mapView.indoorEnabled = true
let mapInsets = UIEdgeInsets(top: 100.0, left: 0.0, bottom: 0.0, right: 0.0)
mapView.padding = mapInsets
//Creates a marker in the center of the map.
//let marker = GMSMarker()
//marker.position = CLLocationCoordinate2D(latitude: 36.2108, longitude: -81.6774)
//marker.title = "ASU"
//marker.snippet = "Boone, NC"
//marker.map = mapView
}
}
My problem is that when I run the app using the simulator, it doesn't show my current gps location anywhere. It does successfully take me to the specified coordinates, it zooms correctly, and it shows the map as the typography map.
So my questions:
What am I doing wrong thats making my current location not show up? (it never asks to have permission)
How can I make my map appear in the background? Like I added the padding to the top so i could add a button through the storyboard but the button did not show up.
Thanks all!
Upvotes: 0
Views: 2875
Reputation: 2269
The problem why there is no padding in the mapView is because you are setting the mapView to be shown as your main view (self.view = mapView) and due to this map is covering the area of the whole screen.
Try to add a subView with padding from the main View and then assign the map View to your subView. Like this -
let subView = UIView(frame: CGRect(x: 0, y: 100, width: self.view.frame.width, height: self.view.frame.height-100))
subView = mapView
self.view.addSubview(subView)
Also for the location issue try to set a default location for your xcode. Refer this for details on how to set location during runtime.
Upvotes: 0
Reputation: 38833
The location on the simulator does not always work, you can:
Upvotes: 1