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.