1
votes

I have a problem when I try to convert an address into latitude and longitude via google service. My address is 1456 sok. no: 10/1 kat:8 Alsancak. The problem is when I write this address to url, correct result is returned, however when I use the php code below, I get zero results.

No problem with result :

http://maps.google.com/maps/api/geocode/json?address=1456%20sok.%20no:%2010/1%20kat:8%20Alsancak&sensor=true

Problem with php :

<?php
header('Content-Type: text/html; charset=utf-8');


getGoogleAddressCoordinates("1456 sok. no: 10/1 kat:8 Alsancak");

function getGoogleAddressCoordinates($address)
{
 //$address = urlencode($address);
 $address = str_replace(" ", "%20", $address);

 $request = file_get_contents('http://maps.google.com/maps/api/geocode/json?address=' . $address . '&sensor=true');
 $json = json_decode($request, true);
 print_r ($json);


}  

?>

1
What exactly do you get back from the request? (What does $request contain?) if it's false, something went wrong with the call itself. Do you have error reporting turned on? - Pekka
the link doesn't work for me..I get ZERO_RESULTS - bitWorking

1 Answers

0
votes

The address 1456 sok. no: 10/1 kat:8 Alsancak is not valid. If you try it in google maps you get zero results, too.

Try it with: 1456 sok. 10/1 Alsancak and uncomment the line $address = urlencode($address); and clear the line $address = str_replace(" ", "%20", $address);.

The url should look like:

http://maps.google.com/maps/api/geocode/json?address=1456%20sok.%2010%2F1%20Alsancak&sensor=true