My array from a PHP file looks like this:
[
{"lat":"4.174475","lon":"73.509564","datetime":"2012-11-23 16:41:40"},
{"lat":"5.17","lon":"73.50633754680894","datetime":"2012-11-23 05:00:00"},
{"lat":"6.17","lon":"73.50633754680894","datetime":"2012-11-01 00:00:00"}
]
When I click the link #Three, it should generate 3 markers using the threeClick()
function. Here is the function.
function threeClick () {
$.getJSON('json.search.php?idcard=<?php echo $idcardno; ?>&limit=3', function(data) {
var location;
$.each(data, function (key, val) {
addMarker(val.lat,val.lon);
});
}
The add marker function is like this (from: Plotting LatLng coordinates from Json Array on Google Map --- the markers all stack up in the same location)
function addMarker(lat,lng) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: map,
icon: "images/mapIcons/red-dot.png"
});
markersArray.push(marker);
}
I generated the map using:
var map;
var markersArray = [];
function initMap() {
var latlng = new google.maps.LatLng(4.174475, 73.509564);
var myOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
}
Can anybody suggest me how I can show the markers on click of a link? What is wrong with this code?
#Three
and calls thethreeClick()
function). – Ben Lee