tags:

views:

60

answers:

1

I am using the Geo::Coder::Many perl module & getting some weird results. When I set Google as the provider, the results are correctly displayed. However, setting the provider to Bing will reverse the latitude & longitude values. For instance:

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";
}

This will return (correctly):

Longitude: -122.085099 Latitude: 37.422782

When I change the provider to Bing, things go awry:

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

This returns:

Longitude: 37.423176 Latitude: -122.085962

Bing consistently returns the results backwards? How would I change this in the module?

+10  A: 

In Geo/Coder/Many/Bing.pm, find the lines:

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

and swap the 0 and 1:

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

This is a bug in Geo-Coder-Many, not Geo::Coder::Bing. Make sure you reported the bug and this fix to the right author.

cjm
ginius
+1: that is just excellent you found that...
drewk