Polyline Tap in Google Maps - ios

I wonder if there is a tap listener for polylines drawn in Google Map. The marker's tap is this:
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
return false
}
Is there any equivalent function for polylines? I believe in Google Maps version 3 for web, you have the ability to add event listener for polylines like this:
google.maps.event.addListener(elines[i], 'click', function()
{
lineClick(this);
});
Thanks!
Is this also possible in ios/swift?

You can use isTappable property of GMSPolyline.
isTappable
If this overlay should cause tap notifications.
polyline.isTappable = true
Whenever the polyline is tapped, the GMSMapViewDelegate method didTapOverlay is called
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
//Write your code here
}
For further information refer https://developers.google.com/maps/documentation/ios-sdk/reference/protocol_g_m_s_map_view_delegate-p.html#a3a2bf2ff4481528f931183cb364c0f4b

Related

How to detect when tap on google map iOS Swift?

I want to check and detect when tap on map marker or anything. Do any delegates exist for this case with google maps in iOS Swift 4?
Thanks.
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
//Write your code here...
}
if the delegate function is not called then set the mapview delegate in viewDidAppear() method or in LocationManager didUpdateLocations() method.

iOS: Google Maps API - Disable info window tap event

The Google Maps api has a didTapInfoWindowOf method that can detect when an info window of a marker has been tapped on.
I am trying to limit this event to only one tap for a period of time.
When I tap on the info window I am making an api call to a backend server and when I get a response back I segue to a different view. The problem is that the user can tap on this info window multiple times thus triggering the api call multiple times.
Is there a way to limit this?
At the moment I am using a locally defined property didTapWindowCount and limit the api call each time it's tapped like so:
var didTapInfoWindowCount = 0
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
didTapInfoWindowCount += 1
// perform api call -- limit to once until done
if didTapInfoWindowCount == 1 {
myAPICall {
// on success
didTapInfoWindowCount = 0
}
}
}
I was wondering if there is a work around or if there is something built into the API?
mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) will be called as many times as the user taps on the info window of the marker.
In order to avoid calling it multiple times in case of API hit, you can use a Bool value.
var didTapInfoWindow = false
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker)
{
if !didTapInfoWindow
{
didTapInfoWindow = true
myAPICall {
// on success
didTapInfoWindow = false
}
}
}

Moving Google Maps Info Window in iOS

So I have a custom info window that appears whenever a user taps a pin in Google Maps. However, I want the info window to appear at the bottom of the screen when the user taps a pin and not above the pin as is default. Basically, when you tap the pin, the map centers on the pin as it does normally but I want the info window to appear at the very bottom of the screen, above the Google Maps logo. I'm currently using this function to show the custom info window:
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) ->
UIView? {
let infoWindow = Bundle.main.loadNibNamed("customInfoWindow", owner: self, options: nil)?.first! as! customInfoWindow
infoWindow.title.text = marker.title
return infoWindow
}
According to the post above, i think you need to add a custom Label rather that the default info window. Implement the below delegate method.
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
// Add a Label on the Map at the desired position,
// get the coordinates of the marker from 'marker.position'
// use the coordinates for displaying it in the label or rev geo to get the address and display (according to the required spec.)
}

Custom info window in IOS google maps sdk

being a newby IOS developer, I'm really struggling to get something basic to work.
I have a need to display this kind of custom info window upon a marker click in the google maps sdk for ios.
Any help would be appreciated.
I've already seen the third party components, but even with them I cannot get this to display. There is always a title, snippet, left image and right image part. The real question is how do you get the gold star rating in the window, with the text next to it.
Make Xib as you want...set Text and image
set delegate GMSMapViewDelegate
-(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
CustomInfoWindow *infoWindow=[[[NSBundle mainBundle] loadNibNamed:#"InfoWindow" owner:self options:nil] objectAtIndex:0];
return infoWindow;
}
https://www.youtube.com/watch?v=ILiBXYscsyY
for more help
see this video..Uploded by google
I was suffering from the same problem of Info window customization in GoogleMapsSdk for iOS for a lot of days, got frustrated & did it my self!
Clean, Completely customizable & Own UIControls with your custom actions code can be found on Github Right here
Happy coding :)
Swift 3.0 Solution
Google Map CustomInfoWindow
//empty the default infowindow
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
return UIView()
}
// reset custom infowindow whenever marker is tapped
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
customInfoView.removeFromSuperview()
// customInfoView.button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
self.view.addSubview(customInfoView)
// Remember to return false
// so marker event is still handled by delegate
return false
}
// let the custom infowindow follows the camera
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if (locationMarker != nil){
let location = locationMarker.position
customInfoView.center = mapView.projection.point(for: location)
}
}
// take care of the close event
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
customInfoView.removeFromSuperview()
}
ended up using SMCalloutView # https://github.com/nfarina/calloutview

Displaying info window when tapped marker in google maps iOS sdk while implementing mapView:didTapMarker: delegate method implemented

Ok it is a long title. I am having trouble when i use google maps iOS sdk. I want to show an info window about a marker which user tapped. According the documentation if snippet and title properties of GMSMarker are both selected info window will be shown when user tapped that marker. But I also implement mapView:didTapMarker: method from GMSMapViewDelegate protocol. If I comment out that method info window is visible otherwise info window is not visible. So how can I show info window when that method implemented?
Implement GMSMapViewDelegate's mapView:didTapMarker: method and make it return false.
Swift Implementation:
func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {
return false
}
For those interested - Swift 5.5 ios 15
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
// return false - show marker info, return true - not show
return false
}

Resources