2012/02/06

さっそく作ってみた。
Google Japan Blog: Google マップが携帯でも表示できるようになりました
HTTP::MobileAgent::Plugin::Locatorを使って緯度経度を取り、GoogleMapの静的画像を表示するサンプルを作ってみた。
ただGoogleMapの座標指定は測地系だったので
http://minken.net/mt/archives/locations.pl の一部を使わせて頂きました。
Perlで投影系変換出来るモジュール誰か知りませんか?

ソースは以下の様な感じ。
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use HTTP::MobileAgent;
use HTTP::MobileAgent::Plugin::Locator;


my $google_map_api_key = "ABQIAAAAS_2fKEdj-fsDOrnYqd4nthTGTkG1t9CC6WQns4yK382vvQcY9RS5JGW4WA0hwZKxfIpKeCjuMOMPIA";

sub geoconv {
    ...
}

sub llh2xyz { # 楕円体座標 -> 直交座標
    ...
}

sub xyz2llh { # 直交座標 -> 楕円体座標
    ...
}

sub deg2dms {
    ...
}

sub dms2deg {
    ...
}

my $q = CGI->new;
my $agent;
my $lat = '';
my $lng = '';
my $location = '';
eval {
  $agent = HTTP::MobileAgent->new;
  $location = $agent->get_location( $q );
  ($lng, $lat) = geoconv($location->lng, $location->lat, $location->datum)
};

print $q->header(-charset=>'Shift_JIS'),<<END;
<html>
<head>
<title>GoogleMap from GPS</title>
</head>
<body>
<h1>What is this?</h1>
Show the Google Map static image from your GPS location.<br />
END

if ($agent && $agent->is_non_mobile) {
  print "<b>Are not mobile agent?</b>";
} else {
  print "<a href=\"device:location?url=gmobile_map.cgi\" lcs>Where?</a>"
    if ($agent->is_docomo);
  print "<a href=\"device:location?url=gmobile_map.cgi\">Where?</a>"
    if ($agent->is_ezweb);
  print "<a href=\"gmobile_map.cgi\" z>Where?</a>"
    if ($agent->is_softbank && !$agent->is_type_3gc);
  print "<a href=\"location:auto?url=gmobile_map.cgi\">Where?</a>"
    if ($agent->is_softbank && $agent->is_type_3gc);
  if ($lat && $lng) {
    print << "END";
<img src="http://maps.google.com/staticmap?center=$lat,$lng&markers=$lat,$lng,red&zoom=18&size=300x200&key=$google_map_api_key"><br />
latitude: $lat<br />
longitude $lng<br />
END
  }
}

print "</body>\n</html>";
若干ずれるのはしょうがないか...
で、動いてる物は
http://mattn.kaoriya.net/cgi-bin/gmobile_map.cgi
携帯端末からアクセス下さい。
キャリア毎のアンカー作ってくれるモジュールも欲しいなぁ...

AWSWORD:google_map
Posted at 16:55 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.