gMap JSON string?
I have the following html;
<div class="event-details-container">
<div class="event-details">
<div class="adress">My adress</div>
<div class="arranger">My arranger</div>
<div class="title">My title</div>
<div class="date">My date</div>
</div>
<div class="event-details">
<div class="adress">My adress 2</div>
<div class="arranger">My arranger 2</div>
<div class="title">My title 2</div>
<div class="date">My date 2</div>
</div>
</div>
And i have the following JS:
var myMarkers = "";
$('.event-details-container .event-details').each(function (index) {
myMarkers += "{ address: " + $(this).children(".adress").text() + ", html: " + "<div style='font-siz:14px;font-weight:bold'>" 开发者_StackOverflow中文版+ $(this).children(".title").text() + "</div>" + $(this).children(".date").text() + "<br/>" + $(this).children(".arranger").text() + "<br/>" + $(this).children(".adress").text() + "},";
});
$(".google-map").gMap({ markers: [myMarkers.slice(0, -1)],
address: "Washington DC, US",
zoom: 6
});
The JS above is based on http://gmap.nurtext.de/ (a plugin for jQuery). But the above code does not work - the map shows, but no markers - so there must be something wrong with the Json "string" i am putting together - but what?
I'm not a javascript guy ... so someone may need to clean this up a bit.
Looking at the docs for the plugin, you need to supply an object containing:
address
zoom
markers
which holds objects containing- a string named
address
- a string named
html
.
var myMarkers = [];
$('.event-details-container .event-details').each(function (index) {
var myHtml = "<div style='font-siz:14px;font-weight:bold'>" +
$(this).children(".title").text() + "</div>" +
$(this).children(".date").text() + "<br/>" +
$(this).children(".arranger").text() + "<br/>" +
$(this).children(".adress").text();
myMarkers.push({ address: $(this).children(".adress").text(), html : myHtml});
});
var myObj = { address : "Washington, DC", zoom : 6, markers : myMarkers };
$(".google-map").gMap(myObj);
(I broke things out a bit so you could get a handle on what's going on)
精彩评论