perl을 쓰기 위해 docker를 사용했다. commit대신 간단한 Dockerrun을 만들었다. commit으로 이미지를 만들면 다음에 다시 만들 수 없다한다.
FROM perl:v5.30.1 MAINTAINER ??? RUN apt-get -y update #GooglaMaps::V3 설치 RUN cpan HTML::GoogleMaps::V3 #https 설정. RUN cpan install LMP::UserAgen Mozilla::CA RUN cpan install LWP::Protocol::https RUN cpan install Bundle::DBI RUN cpan install DBD::mysql
host에 있는 mysql에 접속하기 위해 옵션을 docker에 run 옵션을 줬다.
docker run -it --network=host -e LC_ALL=C.UTF-8 -v ????:/home/ perl:mysql_Map /bin/bash
DBI:mysql로 연결할 때 띄어쓰면 에러를 볼 수 있다. 붙여써야 한다. 이걸 모르고 하루를 날렸다. 또 한글 출력에 문제가 있는데 binmode를 주석처리 했다.
se utf8;
use strict;
use warnings;
use DBI;
use HTML::GoogleMaps::V3;
#아래내용은 구글MAPs 에 사용.
#binmode STDOUT, ":utf8";
my $host ="127.0.0.1";
my $user = "???";
my $password = "?????";
my $database = "?????";
my $tablesname = "????";
#모두 붙여서 사용..
#space 있으면 connect 에러
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $password, {RaiseError => 1});
#한글 설정
my $setkorean="SET NAMES utf8";
$dbh->do($setkorean);
#query 설정.
#my $query = "select * from picture where 태그 like '%??%' limit 10";
#테스트용 query
my $query = "select * from picture where (태그 like '%??%' and gpsLatFloat != 0) limit 10";
#query 실행
#my $sth=$dbh->prepare($query);
#$sth->execute();
#while(my $ref = $sth->fetchrow_hashref()){
# print "Found: $ref->{'perl_tag'}";
#}
#print $sth->rows;
my $map = HTML::GoogleMaps::V3->new(
api_key => "???"
);
#query 실행
my $sth=$dbh->prepare($query);
$sth->execute();
while(my $ref = $sth->fetchrow_hashref()){
print "Found: $ref->{'perl_tag'}";
$map->add_marker(
point => [$ref->{'gpsLongFloat'},$ref->{'gpsLatFloat'}],
html => qq{<a href=$ref->{perl_path}>$ref->{perl_tag}</a>},
);
};#while loop
$sth->finish();
$dbh->disconnect();
my ( $head, $map_div ) = $map->onload_render;
print <<"END_HTML";
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
END_HTML
print $head . "\n";
print <<"END_HTML";
</head>
<body onload="html_googlemaps_initialize()">
END_HTML
print $map_div . "\n";
print <<"END_HTML";
</body>
</html>
END_HTML
이제 marker infoWindows를 이쁘게 설정하면 된다. 아무래도 설명을 입력해야 할 듯 하다.