Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Last active August 29, 2015 13:57
Show Gist options
  • Save MaxPleaner/9924738 to your computer and use it in GitHub Desktop.
Save MaxPleaner/9924738 to your computer and use it in GitHub Desktop.
jquery Google maps example
$(function () {
function initialize() {
// Position map, center @ city center
var page_city_lat = $("#page_city_lat").text();
var page_city_lng = $("#page_city_lng").text();
var mapOptions = {
center: new google.maps.LatLng(page_city_lat, page_city_lng),
zoom: 11
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
// marker @ city center
var myLatlng = new google.maps.LatLng(page_city_lat, page_city_lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: "Hello World!"
});
// Event data config
function concert (x)
{
this.lat = $(x).find(".lat").text();
this.lng = $(x).find(".lng").text();
this.headline = $(x).find(".event_title").text();
this.venue = $(x).find(".venue").text();
};
function mapCoords(x, y)
{
this.coords = new google.maps.LatLng(x, y)
};
var map_ids = $(".map_id");
$.each(map_ids, function (index, value)
{
value2 = concert(value);
value3 = mapCoords(value);
var contentString = 'headline: ' + value2.headline + '<br>' + 'Venue' + value2.venue
var infowindow = new google.maps.InfoWindow(
{
content: contentString
});
var show_marker = new google.maps.Marker(
{
position: value3.coords,
map: map,
title: value2.venue
});
google.maps.event.addListener(marker, 'click', function ()
{
infowindow.open(map, show_marker);
});
};
// Global load function
google.maps.event.addDomListener(window, 'load', initialize);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment