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
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.'"/>';
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:
href
of the anchor in the section "Map with link to Google Maps"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.