Trying to pass dynamically created set of markers to goMap
The client is a realtor with a non-standard intranet which is a "conferencing" system with a very interesting built-in web server (
FirstClass). They post property listings to conferences as email messages, with the property address as the message subject. I'm trying to place the addresses on a Google map using the
goMap() plugin.
I've figured out how to read the conferences and extract the addresses to a web page, either as well-formed JSON or as a string formatted exactly as one would hard code it for goMap, but when I attempt to initialize a map it either rejects it with an error, or ignores it and gives me the default map (of Europe). If I copy/paste the server-generated string into the init function it works just fine.
- <!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MAP TEST</title>
<style type="text/css">
#map { width:600px; height: 400px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false®ion=CA"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.gomap-1.3.0.min.js"></script>
<script>
$(function()
{
var getMarkers = $.get('/Properties/Featured Listings/?Plugin=FRgetAddresses' , function(data)
{
myMarkers = getMarkers.responseText;
console.log('Get retrieved property markers from FirstClass: ' + myMarkers );
$('#map').goMap( myMarkers );
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
The "Plugin=" parameter in the URL is understood by the server, adding &json=1 returns application/json, but that didn't help me, neither did processing the string with $.parseJSON or eval().
That page can be made to supply either of the following (I've tried the first one with and without the curly braces):
- {markers:[{address:"34 Thome Cres. Toronto ON CA",title:"34 Thome Cres., The Annex"},{address: "212 Howland Avenue Toronto ON CA",title: "212 Howland Avenue, Entertainment District"}],maptype:"ROADMAP",zoom: 12, streetViewControl: true}
- {"markers":[{"address":"34ThomeCres. Toronto ON CA","title":"34 Thome Cres., TheAnnex"},{"address":"212 Howland Avenue Toronto ON CA","title": "212 Howland Avenue, Entertainment District"}],"maptype": "ROADMAP","zoom": "12","streetViewControl": "true"}
Hard coded like this it works perfectly:
- $('#map').goMap( {markers: [{address: "34 Thome Cres. Toronto ON CA",title: "34 Thome Cres., The Annex"},{address: "212 Howland Avenue Toronto ON CA",title: "212 Howland Avenue, Entertainment District"}],maptype: "ROADMAP",zoom: 12,streetViewControl: true} );
});
Anybody know how to get that info into my initialization function dynamically? Many thanks.