Is there no way to embed a Google Map into an HTML email?

◇◆丶佛笑我妖孽 提交于 2019-11-28 22:27:37
Neil McGuigan

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

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");

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!