cabs
cabs

Reputation: 13

Grouping Markers by Category in Google Maps

I know this question has been asked before and I have looked at other Stack Overflow examples and elsewhere but have been looking at this code for too long and I am stumped still.

In this fiddle, I have the markers for what will be two of many categories. I tried to set up a categories function displayMarkers to filter and toggle on and off the markers for each category.

I cribbed from these examples with no luck.

When I try to call the displayMarkers function and and pass a parameter (albacore218), I get ReferenceError: albacore218 is not defined.

Data is in JSON and works just fine to populate the data in the marker infowindows. What I don't understand is why the JSON will work in the infowindow but when I try to access the data with the categories function I have no success.

Please let me know what I am missing or am not understanding. Thanks for your help.

Upvotes: 1

Views: 415

Answers (1)

A. Rodas
A. Rodas

Reputation: 20679

You have to enclose the string albacore218 (and also amberjack219) between simple quotes. Otherwise they will be treated as variables.

<input type="button" value="Albacore" onclick="displayMarkers('albacore218');">
<input type="button" value="Amberjack" onclick="displayMarkers('amberjack219');">

Upvotes: 1

Related Questions