I have a PHP script that generates a list of places and I need to add those to a Google map on the same page. In spite of the MANY tutorials online, I haven’t been able to find a straightforward way of doing this. I’m curious to know if there’s a simple javascript/php snippet to do this… without resorting to a JQuery plugin, etc.
<ul id="myPlaces">
<li name="Pan Africa Market" address="1521 1st Ave, Seattle, WA" lat="47.608940" lng="-122.340141" type="restaurant">Pan Africa Market</li>
<li name="Buddha Thai & Bar" address="2222 2nd Ave, Seattle, WA" lat="47.613590" lng="-122.344391" type="bar"/>Buddha Bar</li>
<li name="The Melting Pot" address="14 Mercer St, Seattle, WA" lat="47.624561" lng="-122.356445" type="restaurant"/>Melting Pot</li>
</ul>
The Google Map would simply contain markers with these locations on it. Naturally the locations would change, so they can’t be hard-coded.
Plain jQuery can do this for you with the each function. For the code example you need a google maps object:
See the doku for more informations:
In plain JS it is more code to write and it can be done with the getElementsByTagName function which you can call on the document or a child node: