our
$VERSION
=
'0.39'
;
our
@ISA
= (
'Geo::Coder::Free::Display'
);
sub
html {
my
$self
=
shift
;
my
%args
= (
ref
(
$_
[0]) eq
'HASH'
) ? %{
$_
[0]} :
@_
;
my
$info
=
$self
->{_info};
die
unless
(
$info
);
my
$allowed
= {
'page'
=>
'query'
,
'q'
=> qr/[a-z][A-Z]$/i,
'scantext'
=>
undef
,
'lang'
=>
qr/^[A-Z][A-Z]/
i,
};
my
%params
= %{
$info
->params({
allow
=>
$allowed
})};
delete
$params
{
'page'
};
delete
$params
{
'lang'
};
my
$geocoder
=
$args
{
'geocoder'
};
my
$rc
;
if
(
my
$q
=
$params
{
'q'
}) {
$rc
=
$geocoder
->geocode(
location
=>
$q
);
if
(!
defined
(
$rc
)) {
if
(
my
$country
=
$self
->{_lingua}->country()) {
$rc
=
$geocoder
->geocode(
location
=>
"$q, $country"
);
}
return
'{}'
if
(!
defined
(
$rc
));
}
return
encode_json {
'latitude'
=>
$rc
->lat(),
'longitude'
=>
$rc
->long()
};
}
elsif
(
my
$scantext
=
$params
{
'scantext'
}) {
my
@rc
=
$geocoder
->geocode(
scantext
=>
$scantext
);
if
(
scalar
(
@rc
) > 0) {
my
@locations
;
foreach
my
$l
(
@rc
) {
push
@locations
, {
'latitude'
=>
$l
->lat(),
'longitude'
=>
$l
->long()
};
};
return
encode_json \
@locations
;
}
}
return
'{}'
;
}
1;