donglongqiao9595 2009-12-01 12:03
浏览 38
已采纳

Google Geocode:PHP实现 - 字符编码问题

I'm working with UK address data and also International address data.

I need to geocode the address data for use on a google map. I'm doing this using the HTTP service. Ie/ Constructing a query string and passing it to file_get_contents($THEURL).

I've managed to geocode 80% of the address data perfectly, however those addresses in countries like Norway and Sweeden that contain special characters will not return a geocode.The code returned is 602 (cannot find an address).

Looking into the documentation I can see that the string sent to google must be UTF8 encoded.

I've tried the following to ensure the string is UTF8 encoded / remove the special characters.

1) Using UTF8 encode on the query string - this often results in malformed characters being displayed on the screen.

2) mb_check_encoding reports the string is correctly encoded.

3) Using a function to substitue special characters for thier europiene eqivilents (in the hope google api will compensate.

Can anyone suggest a reason why my method isn't working (whether to do with encoding or not?).

  • 写回答

1条回答 默认 最新

  • douchuang1861 2009-12-01 12:06
    关注

    You need to systematically go through every encoding aspect in your system and define what encoding it is in. Mb_detect_encoding and guesswork are not a good approach here.

    You need to check the encoding of:

    • incoming data
      • pages
      • GET parameters
      • database connection
      • database table collations
    • the script files you work with

    If malformed characters occur, chances are you are using ISO-8859-1 or some other non-UTF-8 encoding somewhere. When everything is clean UTF-8, the request should go through.

    A very good article on the basics is The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C