Programatically generate Google Maps markers (API v3)?

Have PHP spit out javascript code Here's a little convenience javascript function that I wrote to add a marker with a window associated function add_marker(opts, place) { var marker = new google.maps. Marker(opts); marker. Place_id = place.Id; markersplace.

Id = marker; var infowindow = new google.maps. InfoWindow({ content: place. Details }); infowindowsplace.

Id = infowindow; google.maps.event. AddListener(marker, 'click', function() { infowindowsmarker. Place_id.

Open(map,marker); }); } So after declaring that in some javascripty place, you'd then have some PHP that'd probably resemble (and assuming your map is a global called 'map'): script type="text/javascript"> add_marker({ position: new google.maps. LatLng(lat? >, lng?

>), title:title? >, map:map }, { id:'', details:'details? >' }).

Have PHP spit out javascript code. Here's a little convenience javascript function that I wrote to add a marker with a window associated. Function add_marker(opts, place) { var marker = new google.maps.

Marker(opts); marker. Place_id = place. Id; markersplace.Id = marker; var infowindow = new google.maps.

InfoWindow({ content: place. Details }); infowindowsplace.Id = infowindow; google.maps.event. AddListener(marker, 'click', function() { infowindowsmarker.

Place_id. Open(map,marker); }); } So after declaring that in some javascripty place, you'd then have some PHP that'd probably resemble (and assuming your map is a global called 'map'): I haven't tested any of this nor do I have any idea what the data looks like, but that method should work for what you're wanting. I'm not 100% sure what you mean by custom marker generation, because it sounds like you're already doing that, just not through PHP.

My question was more about getting the Google maps marker icon graphic and being able to use that and stick a number over it, sent from PHP. So it's more about image manipulation really or if the API provides a way of doing this on the fly? Cheers.

– Jamie Jun 22 '10 at 7:41.

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: code.google.com/apis/chart/docs/gallery/... Example output: Generated with: chart.apis.google.com/chart?chst=d_map_p....

1 because Google's chart API allows the generated images to be cached by the browser. – josh3736 Aug 4 '10 at 3:49.

I'm not sure if anyone else had this trouble, but I couldn't loop a geocode to plot my points, and Google even consider this an abuse of their service. So my method was to geocode and store the lat/long coordinates at the user input stage instead of the display stage, relieving the bandwidth stress it puts on Google. I'm not sure if this would help but it may help you to perhaps pre-code and store these marker images instead of doing it on the fly.As it stands with your chosen answer, you are relying on google to produce these images while your page is loading, perhaps you may wish to speed up your service by running this code at a different stage and storing the output with the co-ordinates in your PHP database.

Cheers, Dan.

Var marker = new google.maps. Var infowindow = new google.maps. Foreach ($rowset as $row):?

Position: new google.maps. Php echo $row->lat? Php echo $row->lng?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions