I am trying to make my google maps map view only half of the screen. I have resized the map view to be half the screen and also changed my code so it's only the bounds of the map view which is half the screen but it still goes full screen. Anyone got a solution?
// setting up mapView
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
_mapView = [GMSMapView mapWithFrame:_mapView.bounds camera:camera];
_mapView.myLocationEnabled = YES;
self.view = _mapView;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = _mapView;
// Creates a marker in the center of the map.
GMSMarker *marker2 = [[GMSMarker alloc] init];
marker2.position = CLLocationCoordinate2DMake(-36.86, 151.20);
marker2.title = #"Sydney2";
marker2.snippet = #"Australia2";
marker2.map = _mapView;
Thanks,
Curtis
You may can try to add the _mapView as a subview instead of assigning it to self.view.
[self.view addSubview:_mapView];
You can do it with the help of storyboard.
Drag a UIView in your ViewController and add GMSMapView class to the
UIView.
Set the frame size for your UIView using storyboard. Create outlet
for the UIView( name it mapView) and connect it.
In your ViewController class under viewDidLoad add these two lines
two view the google map.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: YOUR_LATITUDE
longitude: YOUR_LONGITUDE zoom:8];
[self.mapView setCamera:camera];
Add marker to the location using following code.
GMSMarker *marker = [[GMSMarker alloc]init];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(YOUR_LATITUDE, YOUR_LONGITUDE);
Related
I have been using GMSMap in my app. I am showing current location in Map. But after zooming the Map it does not show city and state, also path is not visible in the map. I want to I have zooming on map and clear map in the present states and city's. Please assist me for my issue
I am used this code
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:22.6987 longitude:75.8817 zoom:0];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(22.6987, 75.8817);
marker.title = #"indore";
marker.snippet = #"India";
marker.map = mapView;
Now Show Look like please see ones
I have setup a UIView to display a specific region of a Map using Google Maps. I now want to add an image overlay on top of this selected region but I dont know how to calculate the correct coordinates for this. I have set the map with a center coordinate, but the Overlay needs NorthWest and South East coordinates. Can someone help please? I am trying to put an image of a race track over some roads.
Below is my code so far:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:14.5809268
longitude:120.975319
zoom:16.5
bearing:90
viewingAngle:0];
// Indicating the map frame bounds
mapView_ = [GMSMapView mapWithFrame:self.mapViewOnScreen.bounds camera: camera];
mapView_.myLocationEnabled = YES;
// Add as subview the mapview
[self.mapViewOnScreen addSubview: mapView_];
//this is where I need to figure out the coordinates but get stuck...
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(40.712216,-74.22655);
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(40.773941,-74.12544);
GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWest
coordinate:northEast];
//Add track image over the road map to show a race track - roads need to match up
UIImage *icon = [UIImage imageNamed:#"Track.jpg"];
GMSGroundOverlay *overlay =
[GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:icon];
overlay.bearing = 0;
overlay.map = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(14.5809268, 120.975319);
marker.title = #"Race Day";
marker.snippet = #"Manila";
marker.map = mapView_;
}
I haven't tried this, but after doing some research on the API, I think you can achieve what you want by doing the following:
GMSProjection *projection = mapView_.projection;
GMSVisibleRegion visibleRegion = [projection visibleRegion];
GMSCoordinateBounds *coordinateBounds = [[GMSCoordinateBounds alloc] initWithRegion:visibleRegion];
CLLocationCoordinate2D northEast = coordinateBounds.northEast;
CLLocationCoordinate2D southWest = coordinateBounds.southWest;
Hope this helps.
I am building an iOS app.I am using storyboards to build the screens and i have integrated google map in my project.
I want to get location where tap in the map and want to show that location in a label like in Airbnb app.I’m unable to do that,could someone help.
here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
}
Help is appreciated!
You have to use the GMSMapViewDelegate protocol for that. Precisely, the method mapView:didTapAtCoordinate: will do what you require and detect a tap on the map and giving you the tap's coordinate.
To use the method, add the following line in your viewDidLoad:
mapView_.delegate = self;
Then in the same class implement the method:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{
// coordinate contains your coordinate :)
NSLog(#"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude);
}
Update: To add a marker you can do the following:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate{
// coordinate contains your coordinate :)
NSLog(#"did tap at coordinate: (%f, %f)", coordinate.latitude, coordinate.longitude);
// Create the marker and add it to the map
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView_;
// Zoom into the current location
GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithTarget:position zoom:15.0];
[mapView_ animateToCameraPosition:cameraPosition];
}
I have a view controller in a story board and i want to show a google map on it
everything went good, i got the get and i can show the map
my problem is that the camera is not pointing to the marker
here is my code
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"we are in the show stadium");
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.mynewmap = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
}
where mynewmapis an UIView outlet
here is what I see
the marker is on austrail but the camera not pointing to it and the marker is not on the map
If you are working with Storyboards, set the class of mynewmap to GMSMapView in Interface Builder.
And in viewDidLoad just add the camera, you don't need to alloc the view because it will be already allocated:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
self.mynewmap.camera = camera;
}
Or try not creating your view with a Zero rect.. CGRectZero... you could try with:
mapView_ = [GMSMapView mapWithFrame:self.mynewmap.frame camera:camera];
Your current location & (-33.86,151.20) locations are same ya not ... You have enabled userlocation mode. Please try again after comment
//mapView_.myLocationEnabled = YES;
remove this line ... Because It's also tracking userlocation. May be help full.
Add this line after you are done with adding marker
[mapView_ animateToLocation:marker.position];
or use
[mapView_ animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:marker.position.latitude
longitude:marker.position.longitude
zoom:6.0f]];
Faced the same issue in iOS 11, instead of setting the GMSMapView from the storyboards, initialized it in the viewDidLoad method of the viewcontroller like this:
override func viewDidLoad() {
super.viewDidLoad()
// Force the view to layout to get its proper frame
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
// Initialize the GMSMapView with target view's bounds
googleMapView = GMSMapView(frame: self.mapView.bounds)
// Add the GMSMapView to the map container view
self.mapView.addSubview(googleMapView)
}
So i've got a google map in a small view on one of my main views, i'm trying to get a badge to show a location, like google show in their example.. But after ages of trying to get the map to show inside a resizable view (so i can display it within another view), the way i've done it doesn't appear to have a way of adding a badge.
This is my code so far:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
// Create marker
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(-33.86, 151.20);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = #"Hello World";
self.map.camera = camera;
self.map being (in the .h file):
#property (weak, nonatomic) IBOutlet GMSMapView *map;
This is google's example:
// Google map
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
But i seem unable to combine the two
For any one struggling with a similar problem:
This is how i solved using a custom view with a google map + badge
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6];
// set camera location to Novi Sad, Serbia :-)
[self.mymap setCamera:camera]; // set the camera to map
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mymap;