English 中文(简体)
Google Geocode: PHP Implementation - character encoding issues
原标题:

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?).

最佳回答

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!).

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签