user3599016
user3599016

Reputation: 11

PHP Google Maps Api returns ZERO_RESULT in valid request

I am doing project and I need to fill my database with lat lng of address. I decided to use PHP and geocoding and I have big problem. PHP script returns ZERO RESULT, but when I try with web browser I have correct result.

$fulladdress = $street.$city;
$request= "http://maps.googleapis.com/maps/api/geocode/xml?address=".rawurlencode($fulladdress)."&sensor=true";
$xml = simplexml_load_file($request) or die("url not loading");

When i printed $fulladdress, $request and xml status I have this:

?apino Kartuskie http://maps.googleapis.com/maps/api/geocode/xml?address=%3Fapino%20Kartuskie&sensor=true STATUS: ZERO_RESULTS

Upvotes: 0

Views: 795

Answers (3)

marcin32
marcin32

Reputation: 83

As it turns out, if the query/response from google maps api has some diacritical signs, it's necessarry to include http header "Accept-Language'. In my case:

Doesn't work:

curl -s 'http://maps.googleapis.com/maps/api/geocode/json?address=ul.+Zwyciestwa+44%2C+Dobre+Miasto'

Does work:

curl -s \
'http://maps.googleapis.com/maps/api/geocode/json?address=ul.+Zwyciestwa+44%2C+Dobre+Miasto' \
-H 'Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4'

Upvotes: 1

Steve
Steve

Reputation: 20469

You need to translate the polish chars, you can use http://php.net/manual/en/function.iconv.php

$fulladdress = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $street.$city);
$request= "http://maps.googleapis.com/maps/api/geocode/xml?address=".rawurlencode($fulladdress)."&sensor=true";
$xml = simplexml_load_file($request) or die("url not loading");

Upvotes: 1

You need to encode using UTF-8.

http://maps.googleapis.com/maps/api/geocode/xml?address=%C5%81apino%20Kartuskie&sensor=true

Upvotes: 0

Related Questions