GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
I have problems using the webservice with blanks and special characters  XML
Forum Index -> FAQ - frequently asked questions
Author Message
marc



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

Question :
The geocoding webservice does not work with special character like ö or blanks.


Answer :
The parameters for the webservices have to be utf8 url encoded. If you call the webservice with "New York" you have to url encode "New York", otherwise our service will search for "New" and all other parameters afterwards get lost.

"New York" becomes "New%20York" and instead of ö use %C3%B6.


URL Encoding replaces spaces with "+" signs, and unsafe ASCII characters with "%" followed by their hex equivalent. Safe characters are defined in RFC2396. They are the 7-bit ASCII alphanumerics and the mark characters "-_.!~*'()".

Check the documentation of your programming language to see how url encoding is done in your programming language.

Java example :
java.net.UrlEncoder("ö","UTF8");

Perl :
use URI::Escape;
$escapedParameter = uri_escape_utf8("new york");


javascript example :
encodeURIComponent("ö")

(Note that the standard JavaScript escape and unescape functions operate slightly differently: they encode space as "%20", and treat "+" as a safe character.)

Pyton :
Nicolas Laurance has written a client library for geonames :
http://www.zindep.com/blog-zindep/Geoname-python/

[WWW]
zeman



Joined: 30/04/2007 10:46:21
Messages: 2
Offline

I'm using utf8_encode in php to encode strings. It works fine most of the time but I'm getting the occasional odd results like the following when searching for Ryūō Japan...

http://ws.geonames.org/search?name_equals=Ry%u016B%u014D&country=JP&fcode=ppl&fcode=pplc&fcode=ppla&style=full

<status message="missing parameter" value="12"/>
marc



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

Only utf8 encoding is not sufficient. It also needs to be url encoded. Something like this :

rawurlencode(utf8_encode($input))

The result should look like this :
http://dev.geonames.org/search?name_equals=Ry%C5%AB%C5%8D

Regards

Marc

[WWW]
Kristian



Joined: 30/05/2007 18:47:49
Messages: 2
Offline

Hallo

marc wrote:

Perl :
use URI::Escape;
$escapedParameter = uri_escape("new york");
 


Point your browser to CPAN
uri_escape_utf8() is available for UTF-8 url encoding in newer versions of URI::Escape.
It's needed (and nice to use) if the Page where the user typed in the search query uses ISO-8859-1.

Regards
Kristian

EDIT: See also

please excuse my bad english...
marc



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

Thanks, Kristian. I have updated the posting.

[WWW]
PhilBo



Joined: 09/06/2007 05:38:16
Messages: 1
Offline

In Ruby:
require 'cgi'
CGI.escape('new york')
[WWW]
eyeRmonkey



Joined: 02/07/2007 23:32:14
Messages: 9
Offline

In PHP, I am using this:

Code:
$encoding = mb_detect_encoding($query);
 if($encoding == 'UTF-8') {
 	$query_escaped = urlencode($query);
 } else {
 	$query_escaped = urlencode(utf8_encode($query));
 }


It's probably not the best way to go about it, but it works whether you are using UTF-8 for your php files themselves or not.
eyeRmonkey



Joined: 02/07/2007 23:32:14
Messages: 9
Offline

I came up with a better way to accomplish this without using the mbstring library:

Code:
if(is_unicode($query)) {
 	$query_escaped = urlencode($query);
 } else {
 	$query_escaped = urlencode(utf8_encode($query));
 }
bruno bernardino


[Avatar]

Joined: 22/02/2008 17:36:02
Messages: 3
Location: Portugal
Offline

Hi, I'm having problems with the ' character (single quote)...

The URL I'm getting is http://ws.geonames.org/search?name_equals=Bassin%20d%27Arcachon&country=FR&maxRows=30&style=FULL&lang=fr

The GeoName is Bassin d'Arcachon, I'm using php like this:

Code:
$xml = simplexml_load_file("http://ws.geonames.org/search?name_equals=".rawurlencode(utf8_encode(stripslashes($loc)))."&country=$cp&maxRows=30&style=FULL&lang=fr");


where $loc is utf8-decoded and rawurldecoded already.

Does any of you have this problem?

This is the location: http://www.geonames.org/3037252/bassin-d-arcachon.html

If I don't have the option to change it, it probably sucks...
[WWW] [MSN]
marc



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

Hi Bruno

This was a problem on our side with the name_equals parameter. I have fixed it. Thanks for having reported it.

Cheers

Marc

[WWW]
jasonj



Joined: 07/06/2009 12:31:57
Messages: 1
Offline

i seem to be having a similiar issue with Goiás Brazil


http://ws.geonames.org/searchJSON?q=goi%E3%A1s%20brazil&maxRows=10&style=FULL

returns no results but

http://www.geonames.org/search.html?q=Goiás+Brazil&country=

does.
marc



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

your encoding for the json service does not look correct.

It should be "Goi%C3%A1s" instead of "goi%E3%A1s".

Best

Marc

[WWW]
harshadashende



Joined: 26/11/2009 12:14:15
Messages: 3
Offline

I was also facing the same problem for url encoding, but its for VC++. I had written a separate function for the same and now its working. But is there any ready made function or procedure with Geo Names which we can directly apply for url encoding which will work for all types of windows applications?
harshadashende



Joined: 26/11/2009 12:14:15
Messages: 3
Offline

I am getting XML file as a result of "http://ws.geonames.org/search?name=&country=IN&type=xml" .
and in this file, i am getting a city as "Tiruchchirāppalli" . now i want to display this city name as it is, but when i am displaying it, it is shown as "Tiruchchirāppalli" . Is there any solution for this.?
marc



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

You have to use the proper encoding. UTF8 in this case.

Marc

[WWW]
harshadashende



Joined: 26/11/2009 12:14:15
Messages: 3
Offline

Thank you for your reply, but i don't know how to such encoding it in VC++.
Javier Reinoso



Joined: 24/12/2009 15:24:57
Messages: 1
Offline

I am making a software for get geonames, in flash with visual basic or mdm zinc...

When is only the flash, the swf load well the data from geonames.org, but when put in visual basic or mdm zinc, not get the xml answer...

Why???

Here are a complete example with the source, the exe - not work -, the fla, the swf:

http://www.astrodreams.com/aaa/xmlzincsample.rar

I test for download a xml from my web site, and work, but in the exe when attempt to load the data from geonames - for example: http://ws.geonames.org/search?q=london&maxRows=20 -, not work, in the exe the flash not load the xml from geonames and I not know why...

Why?

Good day!!!
eladzaa



Joined: 25/05/2011 10:23:11
Messages: 1
Offline

Hi,

I'm trying to use the wikipediaSearch webservice with the title parameter on the term 'Musée de Cluny'. I'm using URL encoding:

http://ws.geonames.org/wikipediaSearch?&maxRows=1&title=Mus%C3%A9e%20de%20Cluny&username=demo

but getting no results.

the environment is .NET - CSharp.

Wikipedia value is available:

http://en.wikipedia.org/wiki/Mus%C3%A9e_de_Cluny

What am I doing wrong?

Regards,
Elad.
marc



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

The domain name ws.geonames.org is desupported:

http://geonames.wordpress.com/2011/01/28/application-identification-for-free-geonames-web-services/

Please use the domain api.geonames.org and it will work:
http://api.geonames.org/wikipediaSearch?&maxRows=1&title=Mus%C3%A9e%20de%20Cluny&username=demo

Best

Marc

[WWW]
nmfr



Joined: 13/03/2017 17:44:19
Messages: 1
Offline

I am trying to cal the search Web Service to search for "Ivory Coast", using the name parameter, in Portuguese (which is "Costa do Marfim") and i am having trouble figuring out whats wrong:

Name: costa marfim
http://api.geonames.org/searchJSON?maxRows=20&username=frames&featureClass=A&featureClass=P&featureClass=L&orderby=population&name=costa%20marfim&lang=pt&searchlang=pt
Result: Code:
{"totalResultsCount":0,"geonames":[]}

Name: costa do marfim
http://api.geonames.org/searchJSON?maxRows=20&username=frames&featureClass=A&featureClass=P&featureClass=L&orderby=population&name=costa%20do%20marfim&lang=pt&searchlang=pt
Result: Code:
{"totalResultsCount":0,"geonames":[]}

Name: costa marfim (with "+" instead of the "%20")
http://api.geonames.org/searchJSON?maxRows=20&username=frames&featureClass=A&featureClass=P&featureClass=L&orderby=population&name=costa+marfim&lang=pt&searchlang=pt
Result: Code:
{"totalResultsCount":0,"geonames":[]}

Name: marfim costa
http://api.geonames.org/searchJSON?maxRows=20&username=frames&featureClass=A&featureClass=P&featureClass=L&orderby=population&name=marfim%20costa&lang=pt&searchlang=pt
Result: Code:
{"totalResultsCount":1,"geonames":[{"adminCode1":"00","lng":"-5.5","geonameId":2287781,"toponymName":"Republic of Côte d’Ivoire","countryId":"2287781","fcl":"A","population":21058798,"countryCode":"CI","name":"Costa do Marfim","fclName":"country, state, region,...","countryName":"Costa do Marfim","fcodeName":"independent political entity","adminName1":"","lat":"8","fcode":"PCLI"}]}

Name: "costa do marfim"
http://api.geonames.org/searchJSON?maxRows=20&username=frames&featureClass=A&featureClass=P&featureClass=L&orderby=population&name=%22costa%20do%20marfim%22&lang=pt&searchlang=pt
Result: Code:
{"totalResultsCount":1,"geonames":[{"adminCode1":"00","lng":"-5.5","geonameId":2287781,"toponymName":"Republic of Côte d’Ivoire","countryId":"2287781","fcl":"A","population":21058798,"countryCode":"CI","name":"Costa do Marfim","fclName":"country, state, region,...","countryName":"Costa do Marfim","fcodeName":"independent political entity","adminName1":"","lat":"8","fcode":"PCLI"}]}


Is "%20" the correct enconding for white spaces? If so why does name=costa%20marfim return no results?
What search is done when the name is enclosed in double quotes "%22costa%20do%20marfim%22"? Does it search for a exact name?

Thank in advance for the help.
 
Forum Index -> FAQ - frequently asked questions
Go to:   
Powered by JForum 2.1.5 © JForum Team