GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
SearchResult  XML
Forum Index -> General
Author Message
knuthe



Joined: 18/11/2009 08:51:36
Messages: 3
Offline

I have just started including geonames in my java program. Something happens with the search result hit list when I try to get different attributes from the hits.

Let's say I get 100 hits, if I loop over the list I get name, country, latitude and longitude for every hit. If I try to get adminName1 the list suddenly contains only 1 hit. See code below - any of the the get-methods which are commented out affects the number of items in the hit list (btw "stedsnavn" = place name).

I can't find an answer to this anywhere, but I suppose it's because I'm a novise.

The code:
try {
ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
searchCriteria.setQ(stedsnavn);
ToponymSearchResult searchResult = WebService.search(searchCriteria);
List<Toponym>tp = searchResult.getToponyms();
System.out.println("Number of hits = " + tp.size());
int k = 0;
for (int j = 0; j < tp.size(); j++) {
Toponym toponym = tp.get(j);
k++;
System.out.println("Nr " + k);
System.out.println("Name = " + toponym.getName());
System.out.println("CountryName= " + toponym.getCountryName());
System.out.println("Latitude = " + toponym.getLatitude());
System.out.println("Longitude = " + toponym.getLongitude());
/*
System.out.println("AdminCode1 = " + toponym.getAdminCode1());
System.out.println("AdminName1 = " + toponym.getAdminName1());
System.out.println("AdminName2 = " + toponym.getAdminName2());
System.out.println("Alternate = " + toponym.getAlternateNames());
* */
}
} catch ... etc
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

You should look at the Exception you get then you understand.

The adminName1 is not included in the default result, you have to set the 'style' to a higher value to have the field filled.

Best

Marc

[WWW]
knuthe



Joined: 18/11/2009 08:51:36
Messages: 3
Offline

Thanks a lot. The exception explained a lot and setting the Style to FULL gave me all the infomation I asked for:

searchCriteria.setStyle(Style.FULL);

Knut
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team