I hinted at this in my link post, but I thought I’d write up the whole thing in hopes of discussing it. I have a page that will include a Google Map with markers for a number of locations (potentially a large number of markers). For an explanation of how to add markers to a Google Map, check out this page.
So the question is: how do you get the address data from my database to Google Maps?
The process is to geocode the address and then apply the marker to the map. There’s a simple example at that link.
Here are some possible approaches:
- Write some code (PHP in this case) that emits the JavaScript used to geocode the addresses and put the markers on the map. Unfortunately then you have a mixture of JavaScript and PHP code that looks a lot like JavaScript on your page.
- Print out a JavaScript data structure that contains all the information for the markers and then iterate over that data structure in JavaScript.
- Put the map data in hidden elements on the page where it can be extracted using JavaScript. The downside is you have hidden elements on your page. The upside is that your PHP is completely separated from your JavaScript.
- Create a service that returns a JSON data structure of the marker information that can be called using XmlHttpRequest and call that from the page. That offers a clean separation of the JavaScript from the PHP but unfortunately could add latency to the page.
I’ve done some searching to find out how people handle this problem, but haven’t seen any good answers yet. Any ideas?
Storing data for Google Maps
I hinted at this in my link post, but I thought I’d write up the whole thing in hopes of discussing it. I have a page that will include a Google Map with markers for a number of locations (potentially a large number of markers). For an explanation of how to add markers to a Google Map, check out this page.
So the question is: how do you get the address data from my database to Google Maps?
The process is to geocode the address and then apply the marker to the map. There’s a simple example at that link.
Here are some possible approaches:
I’ve done some searching to find out how people handle this problem, but haven’t seen any good answers yet. Any ideas?