I have a question about my info window display. Actually when I just load the page and move around for a bit without searching in the window it seems all to work fine with displaying the news or displaying a no news message. When I start to search for places and than try to click on markers I am getting some weird news like starting with Donald Trump's title or just empty info window at first and after clicking I am getting the same news with Donald Trump title at the top. What shall I add, I mean what code to help you guys to help me. I am on the verge of completing this problem set assignments ( apart from the one invented by me but want to sort the given tasks first).
function addMarker(place)
{
//set longitude and latitude to Floats
var myLat = parseFloat(place.latitude);
var myLng = parseFloat(place.longitude);
//create an icon
var image = new google.maps.MarkerImage(
'http://timvandevall.com/wp-content/uploads/2013/05/printable-treasure-map-for-kids-4.jpg', //url
null, //position
null, //offset
null,
new google.maps.Size(150, 40) //set icon size
)
//create a marker
var marker = new google.maps.Marker
({
position : { lat : myLat, lng : myLng}, //set the position of a marker
title : place.place_name + ' ' + place.postal_code, //the title of marker, visible on hover
map : map, //specify map
icon : image, //set the icon of marker
label : place.place_name //set the lable
});
markers.push(marker); //add marker
//getting the articles
var query = place.place_name;
var content = "<ul\n>";
var content1 = "";
var parameters = {
geo : query
}
$.getJSON("articles.php",parameters)
.done(function(data,textStatus,jqXHR)
{
if(data.length){//checking if there are any info returned
for(var i = 0; i<data.length;i++)
{
content += "<li><a href =" + data[i].link + ">" + data[i].title + "</a></li>"; //if yes populate infowindow with links to news
}
content += "</ul>";
}
else
{
content = "No news today!!"; //if no give user a feedback
}
})
.fail(function(jqXHR, textStatus, errorThrown)
{
console.log("ERROR IS :" + errorThrown.toString());
})
//display the articles while marker is clicked
marker.addListener('click',function(){
showInfo(marker,content);
})
}
Search.php
require(__DIR__ . "/../includes/config.php");
// numerically indexed array of places
$places = [];
// TODO: search database for places matching $_GET["geo"], store in $places
$places = CS50::query("SELECT * FROM places WHERE MATCH(postal_code,place_name,admin_name1) AGAINST (?)",$_GET['geo']);