Uses current JSON format if number of results requested is 1

This commit is contained in:
Stefan Rajkovic 2014-08-08 14:06:06 -04:00
parent 38117df11b
commit b9eb936cac

View File

@ -59,6 +59,10 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin
phantom_node_vector,
route_parameters.zoom_level,
number_of_results);
JSON::Object json_result;
if (phantom_node_vector.empty() || !phantom_node_vector.front().isValid())
{
@ -68,6 +72,9 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin
{
reply.status = http::Reply::ok;
json_result.values["status"] = 0;
if (number_of_results > 1)
{
JSON::Array results;
int vector_length = phantom_node_vector.size();
@ -87,6 +94,19 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin
}
json_result.values["results"] = results;
}
else
{
JSON::Array json_coordinate;
json_coordinate.values.push_back(phantom_node_vector.front().location.lat /
COORDINATE_PRECISION);
json_coordinate.values.push_back(phantom_node_vector.front().location.lon /
COORDINATE_PRECISION);
json_result.values["mapped_coordinate"] = json_coordinate;
std::string temp_string;
facade->GetName(phantom_node_vector.front().name_id, temp_string);
json_result.values["name"] = temp_string;
}
}
JSON::render(reply.content, json_result);
}