The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Geo::Coder::YahooJapan - a simple wrapper for Yahoo Japan Geocoder API

SYNOPSIS

  use Geo::Coder::YahooJapan;
  my $r = lookup("$B?@F`@n8)@n:j;TCf866h0fED(B2-21-6");
  my ($lat, $lng) = ( $r->{latitude}, $r->{longitude} ); # coordinate in TOKYO.

  use Location::GeoTool;
  my $tokyo = Location::GeoTool->create_coord($lat, $lng, 'tokyo', 'degree');
  my $wgs = $tokyo->datum_wgs84;
  my $wgs->format_degree;
  
  # coordinate in WGS87.
  ($lat, $lng) = ($wgs->lat, $wgs->long);

  # if address is ambiguous and the server returns multiple items
  my $r = lookup("$BEl5~ET=BC+6hEl(B");
  # $r->{latitude} and $r->{longitude} contains coordinate of first item.
  my ($lat, $lng) = ( $r->{latitude}, $r->{longitude} );

  # $r->{hits} has the number of candidates.
  if ( $r->{hits} > 1 ) {
        # and $r->{items} contains each candidates infomation.
        foreach ( $r->{items} ) {
                print join "\t", ( $_->{title}, $_->{latitude}, $_->{longitude} );
                print "\n";
        }
  }

DESCRIPTION

Geo::Coder::YahooJapan is a wrapper for Yahoo Japan Geocoder API that is used by the official Yahoo Japan's local search widget http://widgets.yahoo.co.jp/gallery/detail.html?wid=10 . The API returns coordinates in TOKYO datum. if you need the coordinates in WGS84, you need to convert them with Location::GeoTool etc.

lookup(address, opts)

Lookup is an only method in this package that returns coordinate information in an hash reference. When address is not enough precise, the server returns multiple candidates. These candidatse are found in $response->{items}. You can determine geocoding result has multiple candidates or not by seeing $response->{hits}.

You can specify the address in UTF8, SHIFT_JIS, EUC_JP. But the API server does not understand ISO-2022-JP, so you need convert into other character set if your address is written in ISO-2022-JP. In $opts->{num}, you can specify the number of candidates you want to receive when multiple items are found. Default value is 10.

DEPENDENCIES

using LWP::Simple to make a request to the API server.

SEE ALSO

Location::GeoTool can convert coordination systems.

AUTHOR

KUMAGAI Kentaro <ku0522a+cpan@gmail.com>