perl - 地理编码......我做错了什么吗?

标签 perl

我正在使用 Geo::Coder::Many perl 模块并得到一些奇怪的结果。当我将 Google 设置为提供商时,结果会正确显示。但是,将提供商设置为 Bing 将反转纬度和经度值。例如:

use Geo::Coder::Google;
use Geo::Coder::Bing;
use Geo::Coder::Many;
use Geo::Coder::Many::Util qw( country_filter );

# Create the Geo::Coder::Many object, telling it to use a 'weighted random'
# scheduling method
my $options = {
    scheduler_type => 'WRR',
};
my $geocoder_many = Geo::Coder::Many->new( $options );


# Create and add a geocoder
my $Locatorize = Geo::Coder::Google->new( apikey => 'yur Key' );
my $Locatorize_options = {
    geocoder    => $Locatorize,
    daily_limit => 2500, #google has a 2,500 limit/day
};
$geocoder_many->add_geocoder( $Locatorize_options );


my $result = $geocoder_many->geocode( 
    {
        location => '1600 Amphitheatre Parkway Mountain View, CA 94043' 
    }
);

if (defined $result) {
     print "Longitude: ",     $result->{longitude},     "\n";
     print "Latitude: ",      $result->{latitude},      "\n";
}
else {
     print "Failed to geocode!\n";
}

这将返回(正确):

经度:-122.085099 纬度:37.422782

当我将提供商更改为 Bing 时,事情出现了问题:

my $WhereIzIt = Geo::Coder::Bing->new( key => 'Yur key' );
my $WhereIzIt_options = {
    geocoder    => $WhereIzIt,
    daily_limit => 4000,
};
$geocoder_many->add_geocoder( $WhereIzIt_options );

这将返回:

经度:37.423176 纬度:-122.085962

Bing 始终向后返回结果吗?我如何在模块中更改此设置?

最佳答案

Geo/Coder/Many/Bing.pm 中,找到以下行:

longitude   => $raw_reply->{point}->{coordinates}->[0],
latitude    => $raw_reply->{point}->{coordinates}->[1],

交换 0 和 1:

longitude   => $raw_reply->{point}->{coordinates}->[1],
latitude    => $raw_reply->{point}->{coordinates}->[0],

这是 Geo-Coder-Many 中的错误,而不是 Geo::Coder::Bing 中的错误。确保您已将错误和此修复报告给 right author .

关于perl - 地理编码......我做错了什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3847716/

相关文章:

perl - 为什么在Perl中打印 "\n"需要这么长时间?

perl - Perl 中的 chomp 未按预期工作

regex - Perl 正则表达式匹配可选的空白字符

javascript - 如何在 perl 的 JE 引擎中实现 "JS' s require"函数?

regex - 将单词与前导空格匹配

perl - 在进程之间共享一个复杂的对象

perl - 在 Perl Catalyst 应用程序的配置变量上加载模块

perl - 如何在催化剂应用程序上获取 Google OAuth?

oracle - 为什么 perl DBI 在预准备语句 (Oracle) 中添加特殊字符 <*>(小于星号大于)?

perl - 使用 Perl 解析 block 中的文本