I define a variable and I would like to use it to write some HTML 'content' code. However I am new to JavaScript and I am definely doing something wrong.
What I am trying to write the content of an infoWindow bind to a Google Maps marker. I use the content of JSON to write my content in a function called description.
Thanks for your help.
<script>
var json = [
{
"lat":51.5202,
"lng":-0.073101,
"title":"nice single room*--only 135pw- close to BRICK LANE | United Kingdom | Gumtree",
"roTy":"Single room",
"prTy":"House",
"price":"585"
"area":"Brick Lane",
"sta":"Aldgate East",
"laTy":"Private landlord",
"website":"www.gumtree.com",
},
{
"lat":51.5202,
"lng":-0.073101,
"title":"Come and enjoy the Vibrant East London, Many rooms available from 130pw | United Kingdom | Gumtree",
"roTy":"Double room",
"prTy":"House",
"price":"563"
"area":"Brick Lane",
"sta":"Aldgate East",
"laTy":"Private landlord",
"website":"www.gumtree.com",
},
{
"lat":51.5217,
"lng":-0.072289,
"title":"MANY ROOMS AVAILABLE *from 130PW all included | United Kingdom | Gumtree",
"roTy":"Double room",
"prTy":"House",
"price":"563"
"area":"Brick Lane",
"sta":"Shoreditch High Street",
"laTy":"Private landlord",
"website":"www.gumtree.com",
},
]
var myCenter=new google.maps.LatLng(51.5183,-0.068066);
function initialize()
{
var mapProp = {
center:myCenter,
zoom:12,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById ("googleMap"),mapProp);
var infowindow = new google.maps.InfoWindow({
content: ""
});
for (var i = 0, length = json.length; i < length; i++) {
var data=json[i];
var latLng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: data.title
});
var descr = description(data);
bindInfoWindow(marker, map, infowindow, descr);
}
}
function description(data)
{
var entete = '<div id="content">';
entete += '<h1 id="firstHeading" class="firstHeading">'%s'</h1>';
entete += '<div id="bodyContent">';
entete += '<p>roTy in prTy | laTy | £pr per calendar month</p>';
entete += '<p>ar | Closest train station : sta</p>';
entete += '<p>descr</p>';
entete += '<p><a href="link">Access the original ad</a></p>';
entete += '</div></div>';
entete.replace('%s',data.website);
entete.replace('roTy',data.roTy);
entete.replace('prTy',data.roTy);
entete.replace('laTy',data.laTy);
entete.replace('pr',data.price);
entete.replace('ar',data.area);
entete.replace('sta',data.sta);
entete.replace('descr',data.title);
entete.replace('link',data.link);
return entete;
}
function bindInfoWindow(marker, map, infowindow, descri) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(descri);
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>