I have a Map-button that you click (or tap) to show a modal with an embedded Google Map. It works like it should on desktop in different browsers, but on iPhone (and possibly other touch screens) I have to tap the button twice.
Edit: Tried using "ontouchend" for trigger and "touchend" for closing the modal. Now the modal closes as soon as it opens.
The HTML:
<div class="map-modal" id="map-modal">
<div class="map-container">
<div class="the-map" id="map-canvas"></div>
<div class="hide-btn hide-btn--map" onclick="closeModal();"><span class="close hairline"></span><div class="hidden-content">Hide the map</div></div>
</div>
</div>
Button:
<div class="button button--map" onmousedown="calcRoute('<?php echo $location[address1]; ?>', '<?php echo $location[address2]; ?>');">Map</div>
The JavaScript:
function calcRoute(start, end) {
var e = document.getElementById("map-modal");
e.style.display = 'block';
$("body").addClass("modal-open");
google.maps.event.trigger(map, 'resize');
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Sorry, no walking route can be found between these locations");
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);