Jump to content


Photo

Chapter 11 Cryptid Sightings Page


  • Please log in to reply
1 reply to this topic

#1 romdawg

romdawg

    New Member

  • Members
  • Pip
  • 1 posts

Posted 31 October 2013 - 12:49 PM

I'm doing the Cryptid Sightings project in chapter 11 & and I got as far as displaying the map and all the creature sightings I added on the right of the map. I've attached a screen shot of that page. My problem is I can't get any of the markers to appear on the map when I click any of the creature sightings on the right of the map. I even tried running the code that was given in the book and its the same issue: nothing happens when you click any of the "#sight_list" items. Has the google maps API changed in the way it accepts parameters or the way its called or am I doing something wrong? Here is the relevant jquery code:

$(document).ready(function () {
var map;
function initialize() {
var latlng = new google.maps.LatLng(49.890978, -97.126007);
var mapOpts = {
zoom: 9,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOpts);
getAllSightings();
}

initialize();

function getAllSightings() {
$.getJSON("service4.php?action=getAllSightings", function (json) {
if (json.sightings.length > 0) {
$("sight_list").empty();
$.each(json.sightings, function () {
var info = 'Date: ' + this['date'] + ', Type: ' + this['type'];
var $li = $("<li />");
$li.html(info);
$li.addClass("sightings");
$li.attr('id', this['id']);
$li.appendTo("#sight_list");
$li.click(function () {
getSingleSighting(this['id']);
});
$li.appendTo("#sight_list");
});
}
});
}

function getSingleSighting(id) {
$.getJSON("service4.php?action=getSingleSighting&id=" + id, function (json) {
if (json.sightings.length > 0) {

$.each(json.sightings,function () {
var loc = new google.maps.LatLng(this['lat'], this['long']);

var my_marker = new google.maps.Marker({
position: loc,
map: map,
title: this['type']
});
map.setCenter(loc, 20);
});
}
});
}
});

Attached Thumbnails

  • ScreenHunter_62 Oct. 31 13.42.jpg


#2 Aurelia Oberli

Aurelia Oberli

    New Member

  • Members
  • Pip
  • 1 posts

Posted 30 May 2014 - 08:48 AM

No one can help?
I had exactly the same problem. Almost finished the book and now got stuck...
emola




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users