Skip to content

Instantly share code, notes, and snippets.

@gonz
Created December 1, 2010 21:06
Show Gist options
  • Save gonz/724223 to your computer and use it in GitHub Desktop.
Save gonz/724223 to your computer and use it in GitHub Desktop.
Filter/group google maps markers
{# Map #}
<script type="text/javascript">
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 6,
center: new google.maps.LatLng(-32.574592,-55.20605),
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
scrollwheel: false,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
{# Markers #}
var markers = {};
{% for project in project_list %}
{% if project.latitude and project.longitude %}
var marker = new google.maps.Marker({
position: new google.maps.LatLng({{ project.latitude }}, {{ project.longitude }}),
map: map,
title: "{{ project.title }}"
});
{# Marker filter #}
category = '{{ project.category.slug }}'
if (typeof markers[category] == "undefined") {
markers[category] = [marker]
} else {
markers[category].push(marker)
}
{# Marker info window #}
{% url project_detail project.slug as url %}
var infowindow = new google.maps.InfoWindow({
content: '<h2><a href="{{ url }}">{{ project.title }}</a></h2><p>{{ project.short_description }}</p><p>{{ project.location }}</p><p><a href="{{ url }}">{% trans "View details" %} &raquo;</a></p>',
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
{% endif %}
{% endfor %}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment