Using the Google Maps SDK in views other than the main view
Here's how...
- add a UIView into the view controller where you're working
- set it's class to be
GMSMapView
in the identity inspector.
Then control-drag it to your code as you would for any other outlet.
You can lazily instantiate it in its setter...
- (void) setMapView:(GMSMapView *)mapView {
if (!mapView) {
mapView = [[GMSMapView alloc] initWithFrame:mapView.bounds];
}
_mapView = mapView;
}
To display a map Google's sample code becomes...
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
longitude:103.848
zoom:12];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
iOS Google maps sdk - markers are not pointed while using subview instead of main view
Re-Initializing the map was causing the issue. Once it is removed it solved the issue. But Re-initializing GMSMapView is causing the issue ? Its an absurd thing, but it solved the issue.
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
12.778376,
-122.409853);
currentLocation = [[CLLocation alloc] initWithLatitude:position.latitude longitude:position.longitude];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:eventLocation.coordinate.latitude
longitude:eventLocation.coordinate.longitude
zoom:13];
//[self.gmapsView removeFromSuperview];//removing the subview
//self.gmapsView = [GMSMapView mapWithFrame:self.gmapsView.frame camera:camera];
//self.gmapsView.delegate = self;
//self.gmapsView = self.gmapsView; //set map
// [self.view addSubview:self.gmapsView];//Adding back did the magic
self.gmapsView.delegate = self; //set delegate
self.gmapsView.camera = camera; //set camera
GMSMarker *marker = [GMSMarker markerWithPosition:position]; //Adding Marker
marker.map = self.gmapsView;
[self.gmapsView animateToLocation:currentLocation.coordinate];
Unable to recognize gestures on a subview in a GMSMapView
Put the following code:
mapView.settings.consumesGesturesInView = false
From the Google Maps iOS SDK Reference:
Controls whether gestures by users are completely consumed by the
GMSMapView when gestures are enabled (default YES). This prevents
these gestures from being received by parent views.When the GMSMapView is contained by a UIScrollView (or other
scrollable area), this means that gestures on the map will not be
additional consumed as scroll gestures. However, disabling this (set
to NO) may be useful to support complex view hierarchies or
requirements.
Google Maps SDK not displaying properly in UIView?
Finally figured it out...
removed:
self.googleMapView = mapView;
replaced:
[self.googleMapView addSubview:mapView];
Google Maps GMSMapView on custom UIView
If you want to add a mapView
after the loading of the view
, then you need to create an object of GMSMapView
. So break the outlets of your mapView
since it will be created dynamically.
import UIKit
import GoogleMaps
class MapViewController: UIViewController {
//Take a Google Map Object. Don't make outlet from Storyboard, Break the outlet of GMSMapView if you made an outlet
var mapView:GMSMapView?
override func viewDidLoad() {
super.viewDidLoad()
mapView = GMSMapView.map(withFrame: CGRect(x: 100, y: 100, width: 200, height: 200), camera: GMSCameraPosition.camera(withLatitude: 51.050657, longitude: 10.649514, zoom: 5.5))
//so the mapView is of width 200, height 200 and its center is same as center of the self.view
mapView?.center = self.view.center
self.view.addSubview(mapView!)
}
}
Here is the output. mapView
is of width = 200 and height = 200 with center as same as self.view
Unable to navigate Google Map to location
I found solution by change outlet type GMSMapView and setting camera in viewDidLoad method.
in .h file
@property (weak, nonatomic) IBOutlet GMSMapView *mapView;
in viewDidLoad
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:131.20 zoom:6];
self.mapView.camera = camera;
Adding a marker to a GMSMapView subview ios
Your code is getting the map from self.views[0]
, then creating a new map, then adding a marker to that new map. Then you do nothing with the new map, so it won't be displayed. Nothing has been added to the original map, and so you don't see the marker.
I think you need something like this:
var tempMapSubView = self.views[0] as! GMSMapView
var position = CLLocationCoordinate2DMake(37.7833, -122.4167)
var marker = GMSMarker()
marker.position = position
marker.map = tempMapSubView
Related Topics
My App Was Just Rejected for Using the Ad Support Framework. Which Library Is Responsible
How to I Import 3Rd Party Frameworks into Xcode Playground
Uitableview with Static Cells Does Not Appear
How to Change Wkwebview or Uiwebview Default Font
Implementing Hmac and Sha1 Encryption in Swift
Ios8 Photos Framework: How to Get the Name(Or Filename) of a Phasset
How to Get the Udid in iOS 6 and iOS 7
How to Determine If an Nsdate Is Today
Posting Video on Instagram Using Hooks
How Does Apple Notify iOS Apps of Refunds of In-App Purchases (Iap)
Pod Install -Bash: Pod: Command Not Found
Differencebetween Pan and Swipe in iOS
Install Simulator Sdk 4.3 to Xcode 4.4 on Mountain Lion
How to Load an Uiimage into a Swiftui Image Asynchronously
Nsfetchedresultscontroller V.S. Uilocalizedindexedcollation
Application Crashed While Importing Songs from Ipod Library in iPhone for iOS 5.0
Force Landscape Viewcontroller in iOS 7
Uitableviewcell Show White Background and Cannot Be Modified on iOS7