| Author |
Message |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 16/12/2005 14:14:03
|
marc
Joined: 08/12/2005 07:39:47
Messages: 1295
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/
|
 |
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 30/04/2007 10:58:18
|
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"/>
|
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 30/04/2007 16:25:35
|
marc
Joined: 08/12/2005 07:39:47
Messages: 1295
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
|
 |
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 30/05/2007 19:38:18
|
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...
|
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 30/05/2007 20:03:01
|
marc
Joined: 08/12/2005 07:39:47
Messages: 1295
Offline
|
Thanks, Kristian. I have updated the posting.
|
 |
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 09/06/2007 05:40:20
|
PhilBo
Joined: 09/06/2007 05:38:16
Messages: 1
Offline
|
In Ruby:
require 'cgi'
CGI.escape('new york')
|
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 03/07/2007 01:25:56
|
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.
|
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 23/07/2007 01:25:37
|
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));
}
|
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 22/02/2008 17:39:32
|
bruno bernardino
![[Avatar]](/gforum/images/avatar/72da7fd6d1302c0a159f6436d01e9eb0.jpg)
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... |
|
|
 |
![[Post New]](/gforum/templates/default/images/icon_minipost_new.gif) 24/02/2008 11:37:38
|
marc
Joined: 08/12/2005 07:39:47
Messages: 1295
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
|
 |
|
|
 |
|
|