Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically generate Google Maps markers (API v3)

Is it possible to programmatically generate markers in Google? For example, I have a database of services and locations that I want to plot on a Google Map using PHP.

Using the Maps API v3, I have created a map and plotted the services fine using markers and info windows, but what I really want to do is generate numbers (1,2,3,4... etc.) in the default marker bubbles based on the order they get retrieved from the DB. Also, I'd like to change the colour of the marker icon programmatically based on the service type in the database.

I'm using PHP, so don't know if there's a script to do this, but I had hoped that Google would provide this custom marker generation through the API.

like image 476
JamieNewman Avatar asked Apr 11 '26 01:04

JamieNewman


1 Answers

The Maps API requires that you use an image (rather than arbitrary DIV) to display markers, so you would need to render the images server side.

A simple way to do this is to use the Google Charts API to render marker icons: http://code.google.com/apis/chart/docs/gallery/dynamic_icons.html#pins

Example output: alt text

Generated with: https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=C|FF0000|000000

like image 113
plexer Avatar answered Apr 13 '26 02:04

plexer