File Coverage

blib/lib/Geo/Coder/Many/Mapquest.pm
Criterion Covered Total %
statement 15 34 44.1
branch 0 2 0.0
condition n/a
subroutine 5 9 55.5
pod 2 2 100.0
total 22 47 46.8


line stmt bran cond sub pod time code
1             package Geo::Coder::Many::Mapquest;
2              
3 2     2   8 use warnings;
  2         3  
  2         49  
4 2     2   9 use strict;
  2         4  
  2         51  
5 2     2   9 use Carp;
  2         3  
  2         97  
6 2     2   8 use Geo::Coder::Many::Generic;
  2         4  
  2         48  
7 2     2   13 use base 'Geo::Coder::Many::Generic';
  2         3  
  2         752  
8              
9             =head1 NAME
10              
11             Geo::Coder::Many::Mapquest - Mapquest plugin Geo::Coder::Many
12              
13             =head1 VERSION
14              
15             Version 0.02
16              
17             =cut
18              
19             our $VERSION = '0.02';
20              
21             # Requires Geo::Coder::Mapquest 0.05 or above
22 0     0     sub _MIN_MODULE_VERSION { return '0.05'; }
23              
24             =head1 SYNOPSIS
25              
26             This module adds Mapquest support to Geo::Coder::Many.
27              
28             Use as follows:
29              
30             use Geo::Coder::Many;
31             use Geo::Coder::Mapquest;
32            
33             my $options = { };
34             my $geocoder_many = Geo::Coder::Many->new( $options );
35             my $MQ = Geo::Coder::Mapquest->new(apikey => 'Your API key');
36            
37             my $options = {
38             geocoder => $MQ,
39             };
40            
41             $geocoder_many->add_geocoder( $options );
42            
43             my $location = $geocoder_many->geocode(
44             {
45             location => '82 Clerkenwell Road, London, EC1M 5RF'
46             }
47             );
48              
49             =head1 MORE INFO
50              
51             please see http://search.cpan.org/dist/Geo-Coder-Mapquest/
52             and http://developer.mapquest.com/web/products/dev-services/geocoding-ws
53              
54             =head1 SUBROUTINES/METHODS
55              
56             =head2 geocode
57              
58             This is called by Geo::Coder::Many - it sends the geocoding request (via
59             Geo::Coder::Mapquest) and extracts the resulting location, returning it in a
60             standard Geo::Coder::Many::Response.
61              
62             NOTE: currently precision is hard coded to undef! We need to fix it to
63             interpret the code returned by mapquest and assigning a meaningful
64             precision
65              
66             =cut
67              
68             sub geocode {
69 0     0 1   my $self = shift;
70 0           my $location = shift;
71 0 0         defined $location or croak "Geo::Coder::Many::Mapquest::geocode
72             method must be given a location.";
73              
74 0           my @raw_replies = $self->{GeoCoder}->geocode( location => $location );
75 0           my $response = Geo::Coder::Many::Response->new( { location => $location } );
76              
77 0           foreach my $raw_reply ( @raw_replies ) {
78              
79              
80             # need to determine precision from response code
81 0           my $precision =
82             $self->_determine_precision($raw_reply->{geocodeQualityCode});
83              
84 0           my $tmp = {
85             address => $raw_reply->{display_name},
86             country => $raw_reply->{adminArea1},
87             longitude => $raw_reply->{latLng}->{lng},
88             latitude => $raw_reply->{latLng}->{lat},
89             precision => $precision,
90             };
91 0           $response->add_response( $tmp, $self->get_name() );
92             }
93              
94 0           my $http_response = $self->{GeoCoder}->response();
95 0           $response->set_response_code($http_response->code());
96 0           return $response;
97             }
98              
99             sub _determine_precision {
100 0     0     my $self = shift;
101 0           my $code = shift;
102              
103 0           my $precision = undef; # FIXME!
104             # for now all precision set to undef (ie we dont know)
105             # should instead be converting to meaningful number between 0 and 1
106             # based on code
107             # see http://www.mapquestapi.com/geocoding/geocodequality.html
108 0           return $precision;
109             }
110              
111             =head2 get_name
112              
113             Returns the name of the geocoder type - used by Geo::Coder::Many
114              
115             =cut
116              
117 0     0 1   sub get_name { my $self = shift; return 'mapquest ' . $self->{GeoCoder}->VERSION; }
  0            
118              
119             1;
120              
121             __END__