2

I have any adress recorded in my databse corresponding to the customers.

The trouble I met is concerning the including of a googlemap.

I have the following code that convert an adress to the polares.

function getCoordonnees($adresse) {
    $url = "http://maps.google.com/maps/geo?q=" . urlencode($adresse) .
            "&output=csv";
    $csv = file($url);
    $donnees = preg_split("#,#", $csv[0]);
    return $donnees[2] . "," . $donnees[3];
}

The following code returns to me somethinbg like that

48.9381235,2.1329083

When I use the google map I have a picture like that :

enter image description here

Which comes from this url (generated by my function

http://maps.google.com/staticmap?center=48.9381235,2.1329083&zoom=15&size=300x300&maptype=mobile&markers=48.9381235,2.1329083,red&key=***********************KEY*GOOGLEMAP************&sensor=false

When I try to display that picture in my website, An error appears,

<img src="http://maps.google.com/staticmap?center=<?php echo $polar; ?>&zoom=15&size=300x300&maptype=mobile&markers=<?php echo $polar; ?>,red&key=***********************KEY*GOOGLEMAP************&sensor=false" style="border:double 2px" />

Where $polar is the polares.

Including this code in my website returns to me the following mistake :

Failed to load resource: the server responded with a status of 403 (Forbidden) 

I have no idea from where comes this error. Actualy I do not think it comes from google map because on stackoverflow, the picture is displayed.

So I would ask if anybody know where can comes this mistake ? Is is from the server configuration or something else ? I've been looking for that since many times without answer.

Anykind of help will be much appreciated.

Stanislas Piotrowski
  • 2,595
  • 10
  • 40
  • 59
  • Your code looks fine (tested on local html only with the img tag, replacing with coordinates above. Can you guarantee that $polar is returning exactly what is suppose to? You probably can check that on 'view-source' the html page when displaying the error. – rjml Feb 28 '13 at 13:52
  • Thanks for your quick reply, I'm sure at 100% that the polar does return the value expected. For the proof I'm able to display the pictures on stackoverflow. I guess there is some server configuration wrong, or trouble with the cache, but I have no Idea on what is wrong. I've done var_dumpt($polar), and it returns exactly what was expected – Stanislas Piotrowski Feb 28 '13 at 13:56
  • 4
    Stanislas, If i can give you an advice, hide your google maps key to avoid any problem. We don't know if anyone would take it and do something wrong with it. – Nicolas Tonneau Feb 28 '13 at 13:59
  • ok Merci, I've forgotten to do that, I'll do it now – Stanislas Piotrowski Feb 28 '13 at 14:00
  • 1
    On stackoverflow you placed the image tag manually (and not from your php script - I suppose). So your $polar variable is not being applied there. The only thing I can think of is, if the img tag is well constructed, and the only thing that is unpredictable in your code is the echo $polar;, I would investigate further. Plus, I don't test what this code: $csv = file($url); $donnees = preg_split("#,#", $csv[0]); actually does, so... If you could look at ouptut HTML source you can really confirm the the img tag is being well generated – rjml Feb 28 '13 at 14:01
  • thanks for your reply, I've checked, the code is well done generated, the only trouble is that forbidden error. – Stanislas Piotrowski Feb 28 '13 at 14:04
  • If img tag is being well generated (according to php code ) not much I can think of. I believe there is a limit of views on that on google maps API. Don't know if it is that – rjml Feb 28 '13 at 14:07
  • I think you fond the good problem... In fact I used that Api 7 years ago, and Actualy it has become obsolete, because google map said, that for displaying static image no api key are needed. I just removed the key parameter and now it works fine, thanks for your help – Stanislas Piotrowski Feb 28 '13 at 14:16

1 Answers1

1

I was having the same issue and I decided to turn on Google Maps API v2 I already had Google Maps API v3 on but before messing with to many settings I turned them both on. Now it works