Custom info window in IOS google maps sdk - ios

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

Related

Get lat/long from the google mapview

I need to get the lat/long of the location where user taps on the google map view. Is there a necessity to open GooglePlacePickerViewController for this? I need to achieve this in the GMSMapView which is used to show user current location.
It is simple use Delegate method
First set delegate
self.mapView.delegate = self
Then just
extension YourViewController:GMSMapViewDelegate {
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
// USER TAP ON coordinate
}
}
Suggestion : Just go through this tutorial https://medium.freecodecamp.org/how-you-can-use-the-google-maps-sdk-with-ios-using-swift-4-a9bba26d9c4d will not take more than 20 min that my promise will conver all the basic stuff. :)
If you need points of view based system. for example if you want what is exact point where user tap according to view X, Y
Then
you can do it like this
let points:CGPoint = mapView.projection.point(for:coordinates)
Bingo !!
assign delegate like this.
mapView.delegate = self
And use GMSMapViewDelegate to use below method
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("You tapped at Location \(coordinate.latitude), \(coordinate.longitude)")
}

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.)
}

Polyline Tap in Google Maps

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

Mapbox - setCenterCoordinate is deselecting annotations

I'm trying out mapbox (using the ios sdk) and I've run into a problem that I think I've narrowed down pretty far. This is my code:
func centerMap(location: CLLocationCoordinate2D) {
map.setCenterCoordinate(location,
zoomLevel: 14,
animated: true)
}
func mapView(mapView: MGLMapView, didDeselectAnnotation annotation: MGLAnnotation) {
dealDetails.hidden = false
}
func mapView(mapView: MGLMapView, didUpdateUserLocation userLocation: MGLUserLocation?) {
if let currentLocation = userLocation?.coordinate {
centerMap(currentLocation)
}
}
If I don't re-center the map when the user's location is updated (i.e., just commenting out the centerMap(currentLocation) call) then the annotation remains selected. Re-centering the map calls the didDeselectAnnotation function, and I can't figure out how to keep that annotation selected. Any help is appreciated!
I don't think there's any way around that if you update the center coordinate. You'd have to re-select the annotation. However, you probably don't need to do that. If you set the userTrackingMode on the map view to .Follow, it should re-center automatically.

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