46

I have done a good amount of research and have found several "solutions" such as the static maps API and simply sending a link to a Gmap. However is there really no way to actually send someone a Google Map?

Ben Racicot
  • 5,332
  • 12
  • 66
  • 130
  • 1
    Do you mean a javascript map or the image of a map? There's no way you're going to get JavaScript maps working in email. – Neil McGuigan Jun 22 '14 at 19:49
  • 1
    The Static Maps API will give me an image of my map to embed. That would work fine. However I'm talking about an embedded, real deal, iframe map in an HTML email. – Ben Racicot Jun 22 '14 at 20:41
  • From server you can save the image of the map https://stackoverflow.com/questions/9358684/how-do-i-save-the-google-image-map-api-picture-to-my-server?r=SearchResults&s=1|169.9581 – dstonek Jan 05 '19 at 22:38

4 Answers4

38

Well your own research shows that most mail clients don't do iFrames, so what do you think can be done?

This is on purpose by the way. iFrames and JavaScript are security risks that mail services don't want to deal with.

Your best bet is to get a static image of the map and embed it as an image in an HTML email. Put a hyperlink on it to the "full" map on Google Maps.

To do this manually in Gmail:

  1. Go to http://staticmapmaker.com/google/ or similar
  2. Enter the location
  3. Copy the map image to your clipboard and paste it into an email
  4. Copy the href of the anchor in the section "Map with link to Google Maps"
  5. Select the whole image (put the cursor to the right of the image, and press shift + left arrow
  6. Press ctrl+k to hyperlink the image
  7. Paste the url from step 4 into the Web Address field
Community
  • 1
  • 1
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • I found this whilst looking up the same thing. I was hoping Google Maps provided this feature - e.g.: outputting a static image based on query data (lng/lat/width/height). I'm surprised they don't. – hellodaniel Jan 30 '15 at 06:52
  • @hellodaniel I believe they do offer the static maps api which can do something similar to what you describe. – Ben Racicot Mar 12 '15 at 13:00
  • @hellodaniel: http://maps.googleapis.com/maps/api/staticmap?size=200x200&markers=Damrak%2010%20Amsterdam,nl&zoom=13 (the %20 is url-encoding for a space, so that location is "Damrak 10, Amsterdam, NL, at zoomlevel 13") – okdewit Feb 02 '17 at 15:36
14

You can create a static image map and send it by email, doing it in Perl: https://metacpan.org/pod/Geo::Google::StaticMaps::V2

or simply directly by Google: https://developers.google.com/maps/documentation/static-maps/

It should be something like this in HTML part of the e-mail:

<img src="http://maps.googleapis.com/maps/api/staticmap?size=800x600&maptype=hybrid&scale=2&format=png8&sensor=false&path=geodesic%3Atrue%7C-6.9325%2C+37.3916666666667%7C-6.9325%2C+37.3933333333333%7C-6.93388888888889%2C+37.3933333333333%7C-6.93388888888889%2C+37.3916666666667%7C-6.9325%2C+37.3916666666667&zoom=10" width="800" height="600"/>

I have just tried it out and it works like a charm.

Sample code:

#!/usr/bin/perl 
use strict;
use warnings;
use feature ':5.10';
use utf8;
use Geo::Converter::dms2dd qw { dms2dd };
use Geo::Google::StaticMaps::V2;
my $map = Geo::Google::StaticMaps::V2->new(
width    => 800,
height   => 600,
sensor   => 0,
scale    => 2,
zoom     => 16,
format   => "png8",
type     => "hybrid"
);

binmode(STDOUT, ":encoding(UTF-8)");
binmode(STDIN, ":encoding(UTF-8)");
$| = 1;

my %c;

$c{1} = [ '-6 55 57.00', '37 23 30.00' ];
$c{2} = [ '-6 55 57.00', '37 23 36.00' ];
$c{3} = [ '-6 56 02.00', '37 23 36.00' ];
$c{4} = [ '-6 56 02.00', '37 23 30.00' ];
$c{5} = [ '-6 55 57.00', '37 23 30.00' ];

my @location;

foreach my $key (sort keys %c) {
$c{$key}[0]  = dms2dd ({value => $c{$key}[0], is_lat => 1});
$c{$key}[1]  = dms2dd ({value => $c{$key}[1], is_lon => 1});
push(@location, "$c{$key}[0], $c{$key}[1]");
}


my $path = $map->path(locations=>[ @location ], geodesic=>1);
print $map->url;
$map->image;
$map->save("/home/data1/protected/map.png");
Jean Louis
  • 425
  • 1
  • 4
  • 12
0

You can send a link that includes map parameters (Lat,Lgt.. etc) with e-mail to an HTML page on your server which accepts parameters for the map with REST apis and display the full map in browser.Otherwise the only choice is to use the static map concept.Or both can be used , Send the static map image and below that a link to the HTML page which accepts the parameters, prepares map and diplays the real map if user prefers.

Facimus
  • 37
  • 1
  • 7
0

yes there is a way using php and javascript you can pass static map url and pass it through form submission and use in email

Get current location/ Coordinates through javascript

var latlon = position.coords.latitude + "," + position.coords.longitude; var img_url = "https://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=17&size=500x250&sensor=false&key=API_KEY&maptype=roadmap&markers=icon:http://maps.google.com/mapfiles/ms/icons/red-dot.png|"+latlon;

here pass the value to input field

document.getElementById("map_image").value = img_url;

Inside form take input with id=map_image and type hidden than submit form and handle post request on next page

than for handling after submission of form

$map_image_url = $_POST['map_image'];

than you can use this as img in email template

$EMAILTEMPLATE .= '<img src="'.$map_image_url.'"/>';
Hassan Qasim
  • 463
  • 5
  • 5