Author |
Message |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 24/04/2023 22:51:35
|
spechtaculardave
Joined: 24/04/2023 20:14:06
Messages: 2
Offline
|
Hello,
I am trying to add a worldwide city/town autocomplete search box to my weather website. However, I am having trouble getting the returned results from the search web service to be ordered by population for some queries.
Say a user wants to search for the USA city of Philadelphia, so they start by typing “phil”. If I make this api call:
http://api.geonames.org/searchJSON?name=phil&orderby=population&maxRows=200
Why is Philadelphia not included in the 158 returned records? As far as I know, Philadelphia is the largest city in the world that begins with “phil”, so I would expect it to be the first thing returned, but it’s not even in the returned set. The first result is “Phil Campbell” which has a population of 1235, while Philadelphia’s population is about 1.6 million.
I’ve tried adding different combinations of using q instead of name, adding featureClass=P, name_StartsWith=phil, changing orderby to relevance, but nothing has been successful. If I search for “phila”, with one more character instead, Philadelphia is returned successfully at #1 however.
Can anyone provide any guidance on what I may be doing incorrectly? Or offer any advice on a different approach that would achieve the same thing? Are there any examples available that might show better types of calls for a worldwide city/town autocomplete search? Thanks.
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 24/04/2023 22:58:18
|
marc
Joined: 08/12/2005 07:39:47
Messages: 4483
Offline
|
Hi
The parameter is called name_startsWith:
http://api.geonames.org/searchJSON?name_startsWith=phil&orderby=population&maxRows=200
Best Regards
Marc
|
 |
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 25/04/2023 23:37:52
|
spechtaculardave
Joined: 24/04/2023 20:14:06
Messages: 2
Offline
|
Marc,
Thanks for the quick reply. While name_startsWith fixes the issue for "phil", why doesn't it work for "phi"?
http://api.geonames.org/searchJSON?name_startsWith=phi&orderby=population&maxRows=200
Philadelphia is returned as result #3, despite having higher populations than the first and second results.
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 11/02/2025 11:15:25
|
volcanodiscovery
Joined: 10/02/2025 23:11:29
Messages: 1
Offline
|
Hi,
I have the same problem - trying to get a list of the largest places starting with "B", don't know what is wrong about the query:
https://ws.geonames.net/search?name=B&placename_startsWith=B&lang=en&isNameRequired=true&lang=en&maxRows=10&orderby=population&featureClass=P&inclBbox=true&style=FULL&username=volcanodiscovery&token=...
Expect cities like Beijing, Berlin, Belgrad to show up in the top of the list, sorted by their population, but it returns lots of small places in seemingly random order instead.
Thank you for help!
Tom
|
|
 |
|