Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geocoding....did I do something wrong?

Tags:

perl

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?

like image 631
kristen Avatar asked Oct 02 '10 22:10

kristen


People also ask

How accurate is geocoding?

In the reference layer, geocoding accuracy was higher in urban areas compared to rural areas (74.4% vs. 10.5% addresses geocoded to the address or interpolated address level, p < 0.0001); no difference was observed according to the period of residence.

What is an example of geocoding?

Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map.

Is reverse geocoding accurate?

Reverse geocoding results will be imprecise as well. Administrative area geocoding provides the lowest level of geocoding accuracy to connect an area with a location such as a state or province. It is not possible to connect state or provincial level coordinates to a specific address.

What is meant by reverse geocoding?

Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address.


1 Answers

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.

like image 61
cjm Avatar answered Sep 20 '22 18:09

cjm