-1

I am getting the error GoogleMapAPI:createMarkerIcon: Error reading image /path/to/my/image.php when trying to load a map on my website. This only happens on my staging and live systems. Everything works fine on my dev machine. The files are completely the same on all three systems.

I couldn't find a definitive fix for the issue, but others did have it, too because there are a couple of threads on other boards regarding this issue exactly.

The path to the image is correct and the file is accessible.

armin
  • 353
  • 1
  • 3
  • 8

1 Answers1

0

I don't know if anyone is still having this issue. But I spent quite a while on GoogleMapAPI's createMarkerIcon() method because it would load the image just fine on my dev machine, but failed with the message GoogleMapAPI:createMarkerIcon: Error reading image /path/to/image.png on my staging and live machines.

I know that this has been a problem a couple of years ago and couldn't find any threads marked as 'solved' yet. So I figured, i'd share my insights with the world here.

For me, the problem was, that $_SERVER['DOCUMENT_ROOT'] returned a wrong directory. This is most likely the case, if you're using virtual hosts with some aliases configured. As long as you don't call the website over the alias, everything works fine. But as soon as you call the website with the alias, the $_SERVER variable fails to reflect the correct values. This also isn't only the case with the 'DOCUMENT_ROOT' index.

The Maps API, however, uses just this variable to determine the absolute location of the icon image. The workaround is quite simple, if you know what you're looking for. First double check that $_SERVER['DOCUMENT_ROOT'] returns the correct path. If it does in fact return the correct path and you're still getting the error, you'll need to keep looking for a solution. If it doesn't, you can easily write an override method for the API's createMarkerIcon() method. Just replace the $_SERVER['DOCUMENT_ROOT'] variable with your real document root. To retrieve it, use the following line in your index.php to create a constant with the correct path. The final slash is optional, but I recommend you add it.

define('DOCROOT',realpath(dirname(__FILE__).'/'));

That should do. Solved the error for me. Just don't make modifications to the API itself to maintain updatability.

armin
  • 353
  • 1
  • 3
  • 8