Subject: | Problem using non utf8-flagged strings |
It seems that Geo::Coder::Bing requires the address argument to be in
utf8 *octets*. This is not how perl modules should work, but they should
always operate on *characters*. The attached test script shows the
problem. The script does two geolocation attempts with the same string.
In the first case, the string does not have the utf8 flag, in the second
case, it has. Only the second case delivers a result. Note that I added
a test in the middle to show that the two versions of the string are
equal (is $utf8_address, $address).
I guess that the geolocation API expects the arguments to be in utf8. So
somewhere an
encode "utf-8", $string
call is probably missing in the Geo::Coder::Bing module.
Regards,
Slaven
Subject: | utf8.t |
#!/usr/bin/perl -w
# -*- perl -*-
use strict;
use warnings;
use Data::Dumper;
use Devel::Peek;
use Encode;
use Geo::Coder::Bing;
use Test::More tests => 3;
my $VERBOSE = 1;
my $geocoder = Geo::Coder::Bing->new;
my $address = "Rübländerstraße, Berlin, Germany";
Dump $address if $VERBOSE;
my $location = $geocoder->geocode($address);
ok $location, "Supplied string without utf8 flag";
warn Dumper $location if $VERBOSE;
my $utf8_address = decode("iso-8859-1", $address); # force utf8 flag
is $utf8_address, $address;
Dump $utf8_address if $VERBOSE;
$location = $geocoder->geocode($utf8_address);
ok $location, "Supplied string with utf8 flag";
warn Dumper $location if $VERBOSE;
__END__