Added ability to get multiple points from /nearest by using num_results argument
This commit is contained in:
		
							parent
							
								
									1d3932e8c5
								
							
						
					
					
						commit
						38117df11b
					
				| @ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| 
 | ||||
| RouteParameters::RouteParameters() | ||||
|     : zoom_level(18), print_instructions(false), alternate_route(true), geometry(true), | ||||
|       compression(true), deprecatedAPI(false), check_sum(-1) | ||||
|       compression(true), deprecatedAPI(false), check_sum(-1), num_results(1) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| @ -45,6 +45,8 @@ void RouteParameters::setZoomLevel(const short level) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void RouteParameters::setNumberOfResults(const short number) { num_results = number; } | ||||
| 
 | ||||
| void RouteParameters::setAlternateRouteFlag(const bool flag) { alternate_route = flag; } | ||||
| 
 | ||||
| void RouteParameters::setDeprecatedAPIFlag(const std::string &) { deprecatedAPI = true; } | ||||
|  | ||||
| @ -40,6 +40,8 @@ struct RouteParameters | ||||
|     RouteParameters(); | ||||
| 
 | ||||
|     void setZoomLevel(const short level); | ||||
|      | ||||
|     void setNumberOfResults(const short number); | ||||
| 
 | ||||
|     void setAlternateRouteFlag(const bool flag); | ||||
| 
 | ||||
| @ -72,6 +74,7 @@ struct RouteParameters | ||||
|     bool compression; | ||||
|     bool deprecatedAPI; | ||||
|     unsigned check_sum; | ||||
|     short num_results; | ||||
|     std::string service; | ||||
|     std::string output_format; | ||||
|     std::string jsonp_parameter; | ||||
|  | ||||
| @ -53,13 +53,12 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin | ||||
|             reply = http::Reply::StockReply(http::Reply::badRequest); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         int number_of_results = route_parameters.num_results; | ||||
|         std::vector<PhantomNode> phantom_node_vector; | ||||
|         facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates.front(), | ||||
|                                                         phantom_node_vector, | ||||
|                                                         route_parameters.zoom_level, | ||||
|                                                         1); | ||||
| 
 | ||||
|                                                         number_of_results); | ||||
|         JSON::Object json_result; | ||||
|         if (phantom_node_vector.empty() || !phantom_node_vector.front().isValid()) | ||||
|         { | ||||
| @ -69,20 +68,29 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin | ||||
|         { | ||||
|             reply.status = http::Reply::ok; | ||||
|             json_result.values["status"] = 0; | ||||
|             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::Array results; | ||||
|              | ||||
|             int vector_length = phantom_node_vector.size(); | ||||
|             for (int i = 0; i < number_of_results && i < vector_length; i++) | ||||
|             { | ||||
|                 JSON::Array json_coordinate; | ||||
|                 JSON::Object result; | ||||
|                 json_coordinate.values.push_back(phantom_node_vector.at(i).location.lat / | ||||
|                                                  COORDINATE_PRECISION); | ||||
|                 json_coordinate.values.push_back(phantom_node_vector.at(i).location.lon / | ||||
|                                                  COORDINATE_PRECISION); | ||||
|                 result.values["mapped coordinate"] = json_coordinate; | ||||
|                 std::string temp_string; | ||||
|                 facade->GetName(phantom_node_vector.front().name_id, temp_string); | ||||
|                 result.values["name"] = temp_string; | ||||
|                 results.values.push_back(result); | ||||
|             } | ||||
|             json_result.values["results"] = results; | ||||
|         } | ||||
| 
 | ||||
|         JSON::render(reply.content, json_result); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|   private: | ||||
|     DataFacadeT *facade; | ||||
|     std::string descriptor_string; | ||||
|  | ||||
| @ -40,7 +40,7 @@ struct APIGrammar : qi::grammar<Iterator> | ||||
|     explicit APIGrammar(HandlerT * h) : APIGrammar::base_type(api_call), handler(h) | ||||
|     { | ||||
|         api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> *(query); | ||||
|         query    = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | cmp | language | instruction | geometry | alt_route | old_API) ) ; | ||||
|         query    = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | cmp | language | instruction | geometry | alt_route | old_API | num_results) ) ; | ||||
| 
 | ||||
|         zoom        = (-qi::lit('&')) >> qi::lit('z')            >> '=' >> qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)]; | ||||
|         output      = (-qi::lit('&')) >> qi::lit("output")       >> '=' >> string[boost::bind(&HandlerT::setOutputFormat, handler, ::_1)]; | ||||
| @ -54,6 +54,7 @@ struct APIGrammar : qi::grammar<Iterator> | ||||
|         language    = (-qi::lit('&')) >> qi::lit("hl")           >> '=' >> string[boost::bind(&HandlerT::setLanguage, handler, ::_1)]; | ||||
|         alt_route   = (-qi::lit('&')) >> qi::lit("alt")          >> '=' >> qi::bool_[boost::bind(&HandlerT::setAlternateRouteFlag, handler, ::_1)]; | ||||
|         old_API     = (-qi::lit('&')) >> qi::lit("geomformat")   >> '=' >> string[boost::bind(&HandlerT::setDeprecatedAPIFlag, handler, ::_1)]; | ||||
|         num_results = (-qi::lit('&')) >> qi::lit("num_results")  >> '=' >> qi::short_[boost::bind(&HandlerT::setNumberOfResults, handler, ::_1)]; | ||||
| 
 | ||||
|         string            = +(qi::char_("a-zA-Z")); | ||||
|         stringwithDot     = +(qi::char_("a-zA-Z0-9_.-")); | ||||
| @ -63,7 +64,7 @@ struct APIGrammar : qi::grammar<Iterator> | ||||
|     qi::rule<Iterator> api_call, query; | ||||
|     qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location, hint, | ||||
|                                       stringwithDot, stringwithPercent, language, instruction, geometry, | ||||
|                                       cmp, alt_route, old_API; | ||||
|                                       cmp, alt_route, old_API, num_results; | ||||
| 
 | ||||
|     HandlerT * handler; | ||||
| }; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user