2

I'm having some trouble with pset8 in that my addMarker function is not working. To me, it looks correct and I've gone through the documentation several times to make sure but the markers simply aren't appearing.

Can someone please tell me if my code is terribly wrong and help lead me in the right direction? Also it seems that "marker with label" no longer exists and most other solutions here refer to that, so this is just the basic marker.

Also, I have just noticed an error in Chrome's development tab. It says "SyntaxError: Unexpected token W in JSON at position 1" in reference to scripts.js with the update function. I have no idea what this means and I even started over thinking I screwed up somewhere but the error is there from the start! Any ideas what this means and if it's what is causing my marker issue?

Any help greatly appreciated! Thanks.

My addMarker code is below.

function addMarker(place)
{
    var myLatLng = new google.maps.LatLng(parseFloat(place.latitude), parseFloat(place.longitude));

    // create marker

    var marker = new google.maps.Marker({
        map:map,
        position: myLatLng
    }); 

    google.maps.event.addListener(marker, "click", function() { 
        loadinfo(marker, place.postal_code); 
    });

    // add to array
    markers.push(marker); 
}

EDIT: After further investigation, I have determined that the update function consistently fails (hence error) as update.php seems to be returning an invalid JSON - hence, addMarkers never runs! I don't understand why update is failing though as that is entirely the staff's code, I believe. Or am I wrong, is there some part of code I've written that is feeding into update and thus making it fail?

  • 1
    You don't need to add two different click listeners for each marker. You can achieve what you want with only one. Also are you sure your marker doesn't show? Maybe the map is not centered at the location where you put the marker? Can you test it with map.setCenter(marker.getPosition()); – ChrisG Aug 20 '16 at 18:49
  • 1
    Thanks for pointing that out! I was simply playing around with it. I have no markers. I am lead to believe it is because update is failing (see chrome error mentioned above), supposedly because the JSON returned from update.php is not encoded correctly (says the error when run through Firefox)? Because update fails, addMarkers never runs (or so I've concluded?). – Kelly O'Flaherty Aug 21 '16 at 14:55
2

As ChrisG said in the comments, you don't need to add two different click listeners for each marker. I'm comparing your code to mine, and my click listener just uses showInfo(marker, content) -- admittedly, I need to define var content outside of the click lister's anonymous function scope, earlier in the addMarker() function, in order for this to be useful.

Another difference I see between your code and mine is that I used:

var marker = new MarkerWithLabel({
    ... a bunch of stuff ...
});

instead of using

var marker = new google.maps.Marker({
    ... a bunch of stuff ...
});

as you did. That doesn't mean that your way is wrong, but the problem specification does suggest that we should use MarkerWithLabel() instead of google.maps.Marker.

If you choose to do things that way, you may find it helpful to view the MarkerWithLabel examples on GitHub.

The problem specification for Pset8 links to http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.9/ -- but that link is broken!

Luckily, you can find the project on GitHub:

Code is here cause google blew stuff up.

EDIT: (because I can't comment from mobile)

My point re: MarkerWithLabel() is simply that I didn't use the same approach as you did, so I am kind of comparing apples to oranges here.

I like your hunch that the problem is with the JSON returned from update.php. Please update your question to include the JSON returned by visiting update.php directly in the browser, passing in a query that won't return a lot of results.

EDIT2: Busy day today, but I just want you to know that I haven't forgotten about you and I'll post a follow-up as soon as I'm able!

EDIT3: OK, so you found out it was a permission error by using chmod -R 777 *. Now, let's see how much we can restore appropriate permissions without causing the markers to disappear.

Open a new Terminal tab in ide50 and execute the following commands, one at a time, pausing to reload your Mashup website between each command. (Hold down the Shift key while you press the browser's Reload button to make sure that you are bypassing your local cache and reloading everything directly from the server.)

Here are the commands to use, copied from another answer I gave recently. (Please read this for a more complete explanation!)

To restore your permissions to sensible defaults after using chmod -R 777 *, the following commands may help:

cd ~/workspace/pset8
find . -type d | xargs chmod 755
find . -name *.php | xargs chmod 640
find . -name *.html | xargs chmod 644
find . -name *.css | xargs chmod 644
find . -name *.js | xargs chmod 644
chmod 644 ./public/fonts/*

Note: I have not tested these exact commands on my own pset8 directory, because I have not used chmod -R 777 * on it, but I believe that they will help to repair the damage without causing trouble with the Mashup website.

I am confident that these commands will fix your permissions without causing breakage -- but if at any point, your markers disappear, or your site breaks in any other way, let me know what command you executed immediately before that happened and I'll help you to fix it.

By the way, if this helps you to resolve your issue, please let me know by clicking on the green checkmark. Otherwise, this will forever haunt the forum as a zombie unanswered question.

EDIT4: I figured out how to run update.php in the browser by using the contents of $_SERVER['QUERY_STRING'] to recreate a valid query string and append it to the URL for my update.php. It's only a little confusing. For reference, the query string should look something like update.php?ne=41.868658668750605%2C-71.29941358642577&sw=41.771304329637616%2C-71.53218641357421 (those are the coordinates for Providence, Rhode Island.) I know you might not be looking to debug that any more, but I thought I'd include it here just in case someone else wants to know.

| improve this answer | |
  • Sorry, didn't notice the double click event. Removed. I will take a look at your link for marker with label but surely, I should be able to at least see the basic markers on my map? – Kelly O'Flaherty Aug 21 '16 at 14:50
  • 1
    Would you mind telling me how to run update.php in browser? I tried but I don't think I did it correctly. – Kelly O'Flaherty Aug 22 '16 at 15:29
  • I can't do that correctly either. I was confused and thinking of search.php and articles.php. It turns out that update.php is harder to spoof by entering a URL. Have you changed update.php at all? If you're not sure, just unzip the pset8.zip archive again somewhere else (like under ~/workspace/module8/misc/) and run a diff on the update.php files. – hotwebmatter Aug 23 '16 at 3:35
  • Nope, haven't changed anything. And trying to run it in browser just gives a permission error for "unknown". – Kelly O'Flaherty Aug 24 '16 at 18:44
  • 1
    Hi, Matt. Thanks for all your help. I added the permissions as listed in your answer and it seems to be fine. While it has some other problems I've yet to tackle, your answer is a solution for my original problem at least! Thanks so much. – Kelly O'Flaherty Aug 25 '16 at 13:14
-1

You can use the following chmod in your pset directory. It also works.

chmod 700 bin bin/import includes vendor

chmod 711 public public/css public/fonts public/img public/js

chmod 664 includes/*.php public/*.php

chmod 644 public/css/* public/fonts/* public/img/* public/index.html public/js/*

chmod 731 includes vendor

chmod 664 *.json

chmod 731 ../pset8

chmod 731 vendor/library50-php-5 vendor/library50-php-5/CS50 

chmod 664 vendor/library50-php-5/CS50/CS50.php
| improve this answer | |
  • These permissions aren't wrong (at least, not dangerously so) but they are poorly thought out. For example, first you set: chmod 700 bin bin/import includes vendor and then: chmod 731 includes vendor which seems odd. Also, I'm not sure why any directories need to be set chmod 731 at all -- does the group need write access? (Check redd.it/5055ti for better permissions.) But that's not why I'm downvoting you. I'm downvoting because this seems irrelevant to the question that was asked. – hotwebmatter Nov 2 '16 at 19:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .