| 1 | package Geo::Coder::Many::Bing; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use base 'Geo::Coder::Many::Generic'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | Geo::Coder::Many::Bing - Plugin for the Bing geocoder | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | Version 0.02 | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | 1 | our $VERSION = '0.02'; | |
| 19 | |||
| 20 | # Requires Geo::Coder::Bing 0.10 or above | ||
| 21 | 0 | ▶ | sub _MIN_MODULE_VERSION { return '0.10'; } |
|
Subroutine
_MIN_MODULE_VERSION: not called CC=1 SCAR=6.9
| |||
| 22 | |||
| 23 | =head1 SYNOPSIS | ||
| 24 | |||
| 25 | This class wraps Geo::Coder::Bing such that it can be used in | ||
| 26 | Geo::Coder::Many, by converting the results to a standard form. | ||
| 27 | |||
| 28 | Requires Geo::Coder::Bing >= 0.10 | ||
| 29 | |||
| 30 | =head1 METHODS | ||
| 31 | |||
| 32 | =head2 geocode | ||
| 33 | |||
| 34 | Takes a location string, geocodes it using Geo::Coder::Bing, and returns the | ||
| 35 | result in a form understandable to Geo::Coder::Many | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | 0 | ▶ | sub geocode { |
|
Subroutine
geocode: not called CC=2 SCAR=17.9
Pod
documented
| |||
| 40 | 0 | my $self = shift; | |
| 41 | 0 | my $location = shift; | |
| 42 | |||
| 43 | 0 | my @raw_replies = $self->{GeoCoder}->geocode( location => $location ); | |
| 44 | |||
| 45 | 0 | my $http_response = $self->{GeoCoder}->response(); | |
| 46 | |||
| 47 | 0 | my $Response = Geo::Coder::Many::Response->new( { location => $location } ); | |
| 48 | |||
| 49 | 0 | my %convert = ( | |
| 50 | 'High' => 0.9, | ||
| 51 | 'Medium' => 0.5, | ||
| 52 | 'Low' => 0.1, | ||
| 53 | 'Unknown' => undef, | ||
| 54 | ); | ||
| 55 | |||
| 56 | 0 | foreach my $raw_reply (@raw_replies) { | |
| 57 | |||
| 58 | my $tmp = { | ||
| 59 | address => $raw_reply->{address}->{formattedAddress}, | ||
| 60 | country => $raw_reply->{address}->{countryRegion}, | ||
| 61 | latitude => $raw_reply->{point}->{coordinates}->[0], | ||
| 62 | longitude => $raw_reply->{point}->{coordinates}->[1], | ||
| 63 | precision => $convert{$raw_reply->{confidence}}, | ||
| 64 | 0 | }; | |
| 65 | 0 | $Response->add_response( $tmp, $self->get_name()); | |
| 66 | } | ||
| 67 | |||
| 68 | 0 | $Response->set_response_code($http_response->code()); | |
| 69 | 0 | return $Response; | |
| 70 | } | ||
| 71 | |||
| 72 | =head2 get_name | ||
| 73 | |||
| 74 | The short name by which Geo::Coder::Many can refer to this geocoder. | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | 0 | ▶ | sub get_name { my $self = shift; return 'bing ' . $self->{GeoCoder}->VERSION; } |
|
Subroutine
get_name: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 79 | |||
| 80 | 1 | 1; | |
| 81 | |||
| 82 | __END__ | ||