开发者

Querying Chinese addresses in Googlemap API geocoding

开发者 https://www.devze.com 2022-12-18 14:06 出处:网络
I\'m following the demo code from article of phpsqlgeocode.html In the db, I inserted some Chinese addresses, which are utf-8 encoded. I

I'm following the demo code from article of phpsqlgeocode.html

In the db, I inserted some Chinese addresses, which are utf-8 encoded. I found after urlencode the Chinese address, the output of the address would be wrong. Like this one:

http://maps.google.com.tw/maps/geo?output=csv&key=ABQIAAAAfG3KxFZXjEslq8VNxMBpKRR08snBovzCxLQZ9DWwpnzxH-ROPxSAS9Q36m-6OOy0qlwTL6Ht9qp87w&q=%3F%3F%3F%3F%3F%3F%3F%3F%3F132%3F

Then it outputs 200,5,59.3266963,18.2733433 (I can't query this through PHP, but through the browser instead).

This address is actually located in Taichung, Taiwan, but it turns out to be in Sweden, Europe. But when I paste the Chinese address开发者_开发知识库(such as 台中市西屯區智惠 街131巷56號58號60號) in the url, the result turns out to be fine!

How do I make sure it sends out the original Chinese address? How do I avoid urlencode()? I found that removing urlencode() doesn't change anything.

(I've change the MAPS_HOST from maps.google.com to maps.google.com.tw.) (I'm sure my key is right, and other English address geocoding are fine.)


q=%3F%3F%3F%3F%3F%3F%3F%3F%3F132%3F

decodes to:

?????????132?

so something has corrupted the string already before URL-encoding. This could happen if you try to convert the Chinese characters into an encoding that doesn't support Chinese characters, such as Latin-1.

You need to ensure that you're using UTF-8 consistently through your application. In particular you will need to ensure the tables in the database are stored using a UTF-8 character set; in MySQL terms, a UTF-8 collation. The default collation for MySQL otherwise is Latin-1. You'll also want to ensure your connection to the database uses UTF-8 by calling 1mysql_set_charset('utf-8')`.

(I am guessing from your question that you're using PHP.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号