I've set the icon image in my Google map using an absolute url as follows:
icon: 'http://mysite/wp-content/plugins/my_plugin/images/icon1.png'
I set the image in this script: http://mysite/wp-content/plugins/my_plugin/js/myscript.js
Is it possible to use a relative URL? Would the path from the js script be: ../images/icon1.png I've tried every way that I can think of. The Google map is in a WordPress plugin.
WordPress has a lot of PHP functions for determining file paths. I could save file path in PHP and then send it to the javascript script, but I hope that there's a better, simpler way. I don't want to hardcode the image file path as it will be one more thing that can go wrong. Perhaps, there are javascript functions that would work in this case.
Thank you.
Relative paths should work fine, but they need to be relative to the path of the page with the map, not relative to the JS script. If you're using the map script on different pages requiring different relative paths, than a path starting with a slash (e.g. /wp-content/plugins/my_plugin/images/icon1.png
) is the best option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With