douxun7992 2017-01-04 02:05
浏览 36
已采纳

使用PHP编码Google Maps地理编码器的变量

I am trying to encode variables for the URL for the google maps geocoding API with PHP. I have used both urlencode and rawurlencode and I get the same result for

Székesfehérvár, Hungary

PHP returns

Sz%E9kesfeh%E9rv%E1r%2C%20Hungary

Which cannot be decoded by any of the online decoders.

When I encode with the online encoder tools I get:

Sz%C3%A9kesfeh%C3%A9rv%C3%A1r%2C+Hungary

When I plug that in directly to the Google Maps geocoder URL, it is successful. The PHP function fails every time.

This is the code I am using:

function getLatandLong($landmark,$city,$state)
{

global $lat;
global $long;
global $city;
if (!empty($landmark)) {  $encoded_vars = "$landmark,$city,+$state";
} else { $encoded_vars = "$city, $state"; }

$encodedVars = urlencode($encoded_vars);
$doc = new DOMDocument();

$doc->load("http://maps.google.com/maps/api/geocode/xml?address=$encodedVars&sensor=false"); //input address
  • 写回答

1条回答 默认 最新

  • doulian7305 2017-01-04 02:35
    关注

    Well, I tried

    $encodedVars = utf8_encode($encoded_vars);
    

    And that seems to be working, even though the echo shows (probably because I don;t have the right page encoding set on my catch page:

    Székesfehérvár,+Hungary
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择