Change structured_answer id. Added display_name

master
amoraleda 2016-03-17 08:22:22 +00:00
parent 8444ae4485
commit 424ef8d0c4
3 changed files with 23 additions and 12 deletions

View File

@ -5,20 +5,24 @@ use strict;
use DDG::Goodie;
zci is_cached => 0;
zci answer_type => 'where_am_i';
triggers start => 'where am i', 'my location', 'current location', 'my current location';
handle remainder => sub {
return if length($_) or !$loc or !$loc->latitude or !$loc->longitude;
my $display = join(', ', $loc->city, $loc->region, $loc->country_name);
return "",
structured_answer => {
id => 'whereami',
id => 'where_am_i',
name => 'Answer',
data => {
lat => $loc->latitude,
lon => $loc->longitude
lon => $loc->longitude,
display => $display
},
templates => {
group => 'places'

View File

@ -1,26 +1,32 @@
DDH.goodie_where_am_i = DDH.goodie_where_am_i || {};
DDH.where_am_i = DDH.where_am_i || {};
DDG.require('maps', function (DDH) {
"use strict";
DDH.goodie_where_am_i.build = function(ops) {
DDH.where_am_i.build = function(ops) {
var myLatitude = (Math.round(ops.data.lat * 100) / 100).toFixed(2);
var myLongitude = (Math.round(ops.data.lon * 100) / 100).toFixed(2);
var displayName = ops.data.display;
return {
model: 'Place',
view: 'Map',
data: [{
display_name: "Apparent current location",
name: "Apparent current locationn",
display_name: displayName,
name: displayName,
lat: myLatitude,
lon: myLongitude
}],
meta: {
zoomLevel: 3
},
normalize: function(item) {
return {
lat: myLatitude,
lon: myLongitude
};
}
};
};
}(DDH));
}(DDH));

View File

@ -5,17 +5,18 @@ use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => 'whereami';
zci answer_type => 'where_am_i';
zci is_cached => 0;
my @test_loc = (
'',
structured_answer => {
id => 'whereami',
id => 'where_am_i',
name => 'Answer',
data => {
lat => 40.1246,
lon => -75.5385
lon => -75.5385,
display=> "Phoenixville, PA, United States"
},
templates => {
group => 'places'