Difference between revisions of "Search Development"

From Navit's Wiki
Jump to: navigation, search
m (Added to develompent category)
(c highlightning)
Line 2: Line 2:
  
 
First get a handle for searching, specifying the mapset in which the search should be performed.
 
First get a handle for searching, specifying the mapset in which the search should be performed.
 +
<source lang="c">
 
  search_list=search_list_new(struct mapset *ms);
 
  search_list=search_list_new(struct mapset *ms);
 +
</source>
 
Then specify for what to search.
 
Then specify for what to search.
 
The following attributes are supported by the search api, but not all might be possible with all maps
 
The following attributes are supported by the search api, but not all might be possible with all maps
Line 9: Line 11:
 
You can set partial=1 to search for partial matches
 
You can set partial=1 to search for partial matches
  
 +
<source lang="c">
 
  partial=0;
 
  partial=0;
 
  attr.type=attr_country_iso2;
 
  attr.type=attr_country_iso2;
 
  attr.u.str="DE";
 
  attr.u.str="DE";
 
  search_list_search(search_list, &attr, partial);
 
  search_list_search(search_list, &attr, partial);
 +
</source>
  
 
Then you can query the result
 
Then you can query the result
 +
<source lang="c">
 
  result=search_list_get_result(search_list);
 
  result=search_list_get_result(search_list);
 +
</source>
 
If the result is NULL, the search is done and there are no more results
 
If the result is NULL, the search is done and there are no more results
  
 
After the search for a country you can continue to search for a town
 
After the search for a country you can continue to search for a town
  
 +
<source lang="c">
 
  attr.type=attr_town_name;
 
  attr.type=attr_town_name;
 
  attr.u.str="München";
 
  attr.u.str="München";
 
  search_list_search(search_list, &attr, partial);
 
  search_list_search(search_list, &attr, partial);
 +
</source>
  
 
and then for a street
 
and then for a street
 +
<source lang="c">
 
  attr.type=attr_street_name;
 
  attr.type=attr_street_name;
 
  attr.u.str="Marienplatz";
 
  attr.u.str="Marienplatz";
 
  search_list_search(search_list, &attr, partial);
 
  search_list_search(search_list, &attr, partial);
 +
</source>
  
 
If you get several results in search_list_get_result and want to limit them for further searches, you can call
 
If you get several results in search_list_get_result and want to limit them for further searches, you can call
 +
<source lang="c">
 
  search_list_select(search_list, attr.type, result->id, 1);
 
  search_list_select(search_list, attr.type, result->id, 1);
 +
</source>
 
to pick a particular result.
 
to pick a particular result.
  
 
[[Category:Development]]
 
[[Category:Development]]

Revision as of 19:36, 17 December 2012

How to use the search API of navit

First get a handle for searching, specifying the mapset in which the search should be performed.

 search_list=search_list_new(struct mapset *ms);

Then specify for what to search. The following attributes are supported by the search api, but not all might be possible with all maps attr_country_id (ISO numeric country ID),attr_country_iso2 (ISO 2 letter country id),attr_country_iso3 (ISO 3 letter country id) attr_country_car (Car country sign),attr_country_name (country name in the set language), attr_town_postal (Postal Code of a Town), attr_town_name (Name of a Town), attr_street_name (Name of a street) You can set partial=1 to search for partial matches

 partial=0;
 attr.type=attr_country_iso2;
 attr.u.str="DE";
 search_list_search(search_list, &attr, partial);

Then you can query the result

 result=search_list_get_result(search_list);

If the result is NULL, the search is done and there are no more results

After the search for a country you can continue to search for a town

 attr.type=attr_town_name;
 attr.u.str="München";
 search_list_search(search_list, &attr, partial);

and then for a street

 attr.type=attr_street_name;
 attr.u.str="Marienplatz";
 search_list_search(search_list, &attr, partial);

If you get several results in search_list_get_result and want to limit them for further searches, you can call

 search_list_select(search_list, attr.type, result->id, 1);

to pick a particular result.