hnf中に
GPS 33_33_33N 133_33_33E
と書くと
33°33′33.00″N ; 133°33′33.00″Eのようにその場所
*1
へのGoogleマップへリンクされるGPSコマンドを作ってみた。
下のようなgps.phを作って、
#
# gps.ph
#
# how to use
# require 'gps.ph' in config.ph or <theme>/theme.ph
#
# command usage:
# GPS latitude longitude
# => "[mark] latitude ; longitude" which links to GoogleMap showing that place.
#
# (c)2008 ulara
# This library is free software; you can redistribute it
# and/or modify it under the same terms as HyperNikkiSystem itself.
#
package HNS::Hnf::Command;
push @{$Entities{'Inline'}}, 'GPS';
package HNS::Hnf::Command::GPS;
use vars qw(@ISA $Template $NumAttr $IsOneline $mark);
@ISA = qw(HNS::Hnf::Command::Inline);
$AllowCommands = [''];
$Template = qq(<a href="http://maps.google.co.jp/maps?hl=ja&q=%latitude_f,%longitude_f">%mark %latitude_str ; %longitude_str</a>);
$mark = qq(<img src="./icons/web_24.png" width="24" height="24" alt="○" border="0" >);
sub parse_arg($) {
my($tmp) = @_;
my($deg_f,$sgn,$deg,$min,$sec);
if($tmp =~ /^[-+]\d{1,3}\.\d+$/) {
$deg_f = sprintf("%+0.6f",$tmp);
$sgn = ($tmp <=> 0), $tmp=abs($tmp);
$deg = int($tmp), $tmp -= $deg;
$min = int($tmp*60), $tmp -= $min/60;
$sec = $tmp*3600;
return [ $deg_f, $sgn, $deg, $min, $sec ];
}elsif($tmp =~ /^(\d{1,3})_(\d\d)_(\d\d(\.\d\d?)?)([NSEW])$/){
($deg,$min,$sec)=($1,$2,$3);
$sgn=1 if($5 eq "N" || $5 eq "E");
$sgn=-1 if($5 eq "S" || $5 eq "W");
$sgn=0 if($1==0 && $2==0 && $3==0);
$deg_f=sprintf("%+0.6f", $sgn*($deg+$min/60+$sec/3600));
return [$deg_f, $sgn, $deg, $min, $sec ];
}else{
return ["+0.000000", 0, 0, 0, 0];
}
}
sub AsHTML($$$){
my($self,$start,$params) = @_;
my($latitude,$longitude) = split(/ /,$self->{arg_content});
my($lat_f,$lat_sgn,$lat_deg,$lat_min,$lat_sec) = @{&parse_arg($latitude)};
my($lon_f,$lon_sgn,$lon_deg,$lon_min,$lon_sec) = @{&parse_arg($longitude)};
$params->{latitude_f} = $lat_f;
$params->{longitude_f} = $lon_f;
$params->{latitude_str} =
sprintf("%1d°%02d′%05.2f″%1s",
$lat_deg, $lat_min, $lat_sec, ($lat_sgn<0 ? "S" : "N"));
$params->{longitude_str} =
sprintf("%1d°%02d′%05.2f″%1s",
$lon_deg, $lon_min, $lon_sec, ($lon_sgn<0 ? "W" : "E"));
$params->{mark} = $mark;
$self->SUPER::AsHTML($start,$params);
}
1;
これをconfig.ph とか 〈テーマ名〉/theme.ph からrequireする。
中身を見れば分かるとおり、
GPS +35.681579 +139.767079
と書いてもよい。(
35°40′53.68″N ; 139°46′01.48″E)
$Templateを変えれば他の(WGS84測地系な)地図サイトに対応したり、
地図をインラインやポップアップで表示したりできるだろうけど、
めんどくさいからやらない(ぉ