GMSMarker hide/show in GMSMapView in iOS - ios

I used google map sdk for my iOS Application. Here I want to perform GMSMarker hide/show functionality based on the GMSMapView zoom in/zoom out.
Could anyone guide me in correct solution please.

You can add UIPinchGestureRecognizer on your map view.
mapView_.gestureRecognizers = #[ /*add your UIPinchGestureRecognizer instance here*/];
Then in its selector method you can hide/show the marker using:
marker.map = nil; //To hide
marker.map = mapView_; //To show

Related

Google Maps iOS SDK - Stop deselecting marker on map tap

I am adding a simple marker to my mapView, like so:
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(40.763981, -73.971647);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.map = self.mapView;
marker.snippet = #"My Marker";
self.mapView.selectedMarker = marker;
As you can see I select the marker upon placement, however I want to keep this marker selected, showing the infoview, at all times it is on the map.
Currently, if I tap elsewhere on the map, the infoview is hidden (but the marker stays)

Centering custom marker GMSMapView

I am trying to position my custom marker in iOS(Objective-C) with Google Maps.
Map view is all showing up fine with marker, however, moving the map will take the marker with it as its fetching current location. What I am looking for is the have it set to center of the map container, which will then fetch coordinates of map pin and display in search bar.
I am thinking I am doing this in reverse? I added the customer marker as a UIImage of the map container however it still does not show. Should I be getting the location from the position of the map marker, and then reverse geocoding address from there.
- (void)addPins:(float)lat andLng:(float)lng andName:(NSString*)strName withAddress:(NSString*)strAddr
{
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(currentUserLocation.coordinate.latitude, currentUserLocation.coordinate.longitude);
NSLog(#"lat : %f, lng : %f", lat, lng);
marker.icon = [UIImage imageNamed:#"map_pin"];
marker.title = strName;
marker.snippet = strAddr;
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = mapView;
}
The user needs to be able to search and set their address, besides their current location.
Thanks
Use your mapView delegate and use the responder to re-center your pin and re-fire your geocoordinate lookup.
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
Edit: If GMS Maps does not have these delegates, the approach may work with using whatever [mapView didUpdate]callback they have documented.
You can set GMSCameraPosition for centering your marker
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:"YOUR LATITUDE"
longitude:"YOUR LONGITUDE"
zoom:centerZoom];
"YOUT GMSMAPVIEW" = [GMSMapView mapWithFrame:"YOUR VIEW".bounds camera:camera];

How to show Blinking gms marker on gmsmap view?

I am using google map , and I have used GMS Map view.In map view I have created one GMS marker for current location and it is updating every one second with current latitude and longitude value.I used this code:
mMapView = [[GMSMapView alloc]init];
mMapView.delegate = self;
mMapView.myLocationEnabled = YES;
mMapView.frame = CGRectMake(0, 95, self.view.frame.size.width,self.view.frame.size.height -205);
GMSMarker *disMarker = [GMSMarker markerWithPosition:coordinateEndLocation];
disMarker.snippet = #"current Location";
disMarker.animated = YES;
disMarker.map = mMapView;
But I want that this marker should be blinking in every second and this one in not blinking.Any Suggestions?
GMSMarker doesn't by default provides a blinking marker.. you have to create 1 by yourself.. You can try blinking marker by using a timer and changing the opacity property of your marker between 0 and 1.. - (float) opacity [read, write, assign] have a look on this property of your GMSMarker

iOS google maps sdk custom call out view and marker centering

Hi guys I am working with Google maps sdk now, I kinda have two doubts:
Callouts:
How to customize callouts, I had a hard time trying to figure out a way to customize the existing stuff but could not. I found this though.
GMSMarkers:
I want to center the marker in the map view i.e, the marker should be in a particular position that I set and also the current zoom level should also be maintained.
I did the marker centering but now I am showing a callout from the marker and I want to center the callout to be centered.
Thanks in advance.
For the GMSMarker question: You have to create a camera that points to the marker position and then set the mapview camera to it
somemarker = [[GMSMarker alloc] init];
somemarker.position = CLLocationCoordinate2DMake(lat, lng);
somemarker.map = mapView;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:somemarker.position.latitude longitude:somemarker.position.longitude zoom:13];
[mapView setCamera:camera];
You can see my SO answer here that shows how to do custom infowindows (callouts).
You can do this by using this code -
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
NSLog(#"the post title is :%# %#",marker.userData,marker.title);
CustomInfoWindow *view = [[[NSBundle mainBundle] loadNibNamed:#"CustomInfoWindow" owner:self options:nil] objectAtIndex:0]; // Your Created Custom View XIB.
UILabel *theLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50,150, 50)];// Create a Custom Label and add it on the custom view.
theLabel.text = marker.title; // marker.title is the title of pin.
[view addSubview:theLabel];
return view;
}

Remove markers from google maps iOS

I am building an iOS app using storyboards and Google Maps. Using iOS6
My application features the split view navigation as seen in the facebook app
On my left view I am selecting an item in a list which has lat/long cords and showing it on my map on the following method
- (void)viewWillAppear:(BOOL)animated
I would like to remove all markers in this method before I add another one (so only one marker is on the map), is there a way to do this? Below is my code to add a marker to the mapView
Thanks in advance - Jon
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:poi.lat
longitude:poi.lon
zoom:15];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;
mapView.mapType = kGMSTypeHybrid;
//Allows you to tap a marker and have camera pan to it
mapView.delegate = self;
}
-(void)viewWillAppear:(BOOL)animated
{
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(poi.lat, poi.lon);
options.title = poi.title;
options.snippet = poi.description;
options.icon = [UIImage imageNamed:#"flag-red.png"];
[mapView addMarkerWithOptions:options];
[mapView animateToLocation:options.position];
[mapView animateToBearing:0];
[mapView animateToViewingAngle:0];
}
To remove all markers
mapView.clear()
To remove a specific marker
myMarker.map = nil
To remove all markers simple do:
[self.mapView clear];
Please refer to the Google Map documentation: Google Maps SDK for iOS
Please refer to the section title "Remove a marker". Always check documentation for such methods.
mapView.clear()
// It will clear all markers from GMSMapView.
To remove a single marker from map.
yourMarkerName.map = nil
To remove all markers from map.
yourMapViewName.clear()
It's a little bit tricky here if you want to remove only one marker among a group of your markers.
let marker = GMSMarker(position: coordinate) //
marker.icon = UIImage(named: "ic_pin_marker")
marker.map = mapView
mapView.selectedMarker = marker // the specific marker you want to remove or modify by set it as selectedMarker on the map.
then you want to remove or modify
mapView.selectedMarker.map = nil //example to remove the marker form the map.
Hopefully useful with your condition.
mapView.clear() is not a good idea .
because The Places SDK for iOS enforces a default limit of 1,000 requests per 24 hour period.(If your app exceeds the limit, the app will start failing. Verify your identity to get 150,000 requests per 24 hour period.)
whit mapView.clear() the requests increase .
the best way is clear each marker and polylines .

Resources