有没有办法将 Google 地图嵌入 HTML 电子邮件中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24355007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:06:54  来源:igfitidea点击:

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

htmlgoogle-mapsiframehtml-email

提问by Ben Racicot

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

我做了大量的研究,并找到了几个“解决方案”,例如静态地图 API和简单地发送到 Gmap 的链接。然而,真的没有办法真正向某人发送谷歌地图吗?

采纳答案by Neil McGuigan

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

您自己的研究表明,大多数邮件客户端不支持 iFrame,那么您认为可以做什么?

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

顺便说一下,这是故意的。iFrame 和 JavaScript 是邮件服务不想处理的安全风险。

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

最好的办法是获取地图的静态图像并将其作为图像嵌入HTML 电子邮件中。在其上放置一个指向 Google 地图上“完整”地图的超链接。

To do this manually in Gmail:

要在 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 hrefof 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+kto hyperlink the image
  7. Paste the url from step 4 into the Web Address field
  1. 转到http://staticmapmaker.com/google/或类似的
  2. 输入位置
  3. 将地图图像复制到剪贴板并将其粘贴到电子邮件中
  4. 复制href“带有 Google 地图链接的地图”部分中的锚点
  5. 选择整个图像(将光标放在图像右侧,然后按shift+left arrow
  6. ctrl+k超链接图像
  7. 将步骤 4 中的 url 粘贴到 Web 地址字段中

回答by Mr. Rosario Maddox

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

您可以创建静态图像地图并通过电子邮件发送,在 Perl 中进行:https://metacpan.org/pod/Geo::Google::StaticMaps:: V2

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

或直接由 Google 提供:https: //developers.google.com/maps/documentation/static-maps/

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

在电子邮件的 HTML 部分应该是这样的:

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

回答by Facimus

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.

您可以通过电子邮件将包含地图参数(纬度、纬度等)的链接发送到服务器上的 HTML 页面,该页面接受带有 REST api 的地图参数并在浏览器中显示完整地图。否则唯一的选择是使用静态地图概念。或者两者都可以使用,发送静态地图图像和下面的链接到接受参数的HTML页面,如果用户愿意,准备地图并显示真实地图。