You can use the mailto of JavaScript. You can change the values of different parameters to suit your email.
So in your code, you can put something like this as your content in your InfoWindow:
var infowindow = new google.maps.InfoWindow({
content :'<div id="content">'+
'<a href="mailto:username@example.com?subject=Subject&body=message%20goes%20here">'+
'Click to Email</a> '+
'</div>'
});
The following is a sample code. To see how this works, you can copy and save it as html file and run it in your browser. Please note to change your API Key:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Info Windows</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.
function initMap() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var contentString = '<div id="content">'+
'<a href="mailto:username@example.com?subject=Subject&body=message%20goes%20here">'+
'Click to Email</a> '+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: uluru,
map: map,
title: 'Uluru (Ayers Rock)'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=CHANGE_API_KEY_HERE&callback=initMap">
</script>
</body>
</html>
Hope this helps!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…