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

后端 未结 4 1835
刺人心
刺人心 2020-12-15 03:16

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

4条回答
  •  佛祖请我去吃肉
    2020-12-15 03:59

    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:

    
    

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

提交回复
热议问题