How can I intercept touches on a marker in Google Maps SDK for iOS? - google-maps-sdk-ios

I am new to the Google Maps SDK for iOS. When a user clicks on a marker, instead of showing the default info window with a title and snippet, I would like to direct them somewhere else in my app (such as a modal view controller). I have searched through the header files and online and I can't seem to find anything relating to touch events on markers. Does anyone have suggestions or workarounds?

I believe what you want is to add the delegate and override the didTapMarker method
/**
* Called after a marker has been tapped.
*
* #param mapView The map view that was pressed.
* #param marker The marker that was pressed.
* #return YES if this delegate handled the tap event, which prevents the map
* from performing its default selection behavior, and NO if the map
* should continue with its default selection behavior.
*/
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(id<GMSMarker>)marker;

Related

Flutter Google Maps, how to detect map area change by user, not by controller

I am using Google Maps to display markers on the map and other widgets to describe each marker on the map. I have successfully implemented when the user tab on a widget, the map area will change to make the matching marker to be the center of the map.
I also have the 'Search this area' button to search the map area.
The hard part is to control how to hide/display the 'Search this area' button.
So far, I have implemented it to display when the map area is changed. However, it causes the button to appear every time the map area changed by the user tab on a widget.
I would like to only detect the map area change by the user manually such as pinch zoom in / out, drag etc.
You can use the Listener widget to listen for onPointerMove on your map. Like this,
Listener(
onPointerMove: (move) {
// This will trigger when a user will drag the map
},
child: map);
Mind that onPointerMove is called many times during user drag and is not called when the user taps on map buttons like the map zoom buttons.
If you want only one call after the end of the user interaction and to also get events from the map buttons, you can use onPointerUp instead.

Can you customize the current location marker in react native maps?

I'd like to use a custom marker image instead of the pulsing blue dot - is there a way to customize this in react native maps using apple maps for ios and google maps for Android?
As far as I know, you cannot change the default current location dot. A work around is to pass the user's location into a <Marker /> with your custom image and turn off showsUserLocation to hide the default blue dot. Here are the Marker docs.
Then you can track the user's location using Geolocation.watchPosition. If you set the user's location to state it will trigger a rerender when the user moves.
You can create a custom marker and hook up an event listener to track the user and update the location of the marker as your user moves.
This event listener is available within the framework.
https://facebook.github.io/react-native/docs/geolocation.html#watchposition

How to properly hide markers in google maps?

I am trying to add a bunch of markers to a map with show/hide buttons for each category of markers. Adding a marker from stored db data puts them on the map and makes them clickable, but they won't respond to setMap(null) unless that call is through google.event.addListener(marker, ...). Calling it from a standard js button onclick event, or via google.event.addDomListener(marker, ...) doesn't work.
Also maybe helpful to note is that when I call marker.setAnimation(BOUNCE) the marker starts bouncing but it looks like there is a duplicate marker under it. Similarly, if I drag the marker it's as if an unmovable duplicate is created right under it.
Thoughts? This is super frustrating!
Just like this taken from here ? Are you trying to avoid google maps api's google.maps.event.addDomListener? Why? You can use it to listen to your button's click event too. just as in:
var YourButton = document.getElementById('myButton');
function HideMarkers() {
// Hide us
}
google.maps.event.addDomListener(YourButton, 'click', HideMarkers);
customized for you from. For the second part, seeming like double markers I suppose we need some code..
This turned out to be purely user error. I am using firebase to store map data without a server backend and was adding duplicate markers. This explains the "inability to hide" and also the appearance of duplicate markers when dragging or animating.
The reason it was working from a click event on the marker was that both duplicate markers were receiving the click event and so both were being hidden.
setMap appears to be perfectly reliable when used in or out of google event handlers.

Google map api v3 - show default bubbles

I'm using the gmaps api to draw a custom map, though at this point, it's bare-bones and I need to enable some of the default behavior that comes with embedded maps, namely bubbles for public transport that show up on click. How would I do that?

GoogleMaps API v3 - Need help with two "click" event scenarios. Need similar functionality to v2 API

In version 2 of the API the map click event returned an Overlay, LatLng, Overlaylatlng.
I used this to create a generic map event that would either retrieve the coordinates of the Map click event, or return the coordinates of a Marker or other type of Overlay.
Now that API v3 doesn't return the Overlay or Overlaylatlng during the map click event, how can I go about creating a generic "click" event for the map that works if the user clicks on a marker or overlay? I really don't want to create a click event for each marker I have on my page as I am creating anywhere from a handful to a couple thousand markers.
Also, I had to create a custom ImageMapType in order to display the StreetViewOverlay like we could do in v2 of the API because I couldn't find anywhere that told me how to add the StreetViewOverlay without the pegman icon. How can I go about retrieving the LatLng coordinates of a click on this overlay type as well?
You will need to add a click listener to each overlay you add. You can do this in a createMarker function to reduce your code overhead.
Clicks on markers do not trigger a click event on the map at all.