Skip to content

Instantly share code, notes, and snippets.

@bovan
Created November 19, 2010 18:31
Show Gist options
  • Save bovan/706915 to your computer and use it in GitHub Desktop.
Save bovan/706915 to your computer and use it in GitHub Desktop.
<h1> Hallo </h1>
<div id="map_canvas" style="width: 400px; height: 600px"></div>
<script type="text/javascript">
/* Fetches a JSON file with the data */
/* stors it in jquery data and starts map when successful */
function fetchData(){
$.ajax({
type: "GET",
url: "/vegvesen/data",
dataType: "json",
success: function(data) {
$('body').data('trafikk', data.Searchresult['Result-array'].Result.Messages.Message);
startMap();
}
});
}
/* starts the google map */
/* requires data to be loaded to set markers properly */
function startMap()
{
//this gets invoked after store.js loads
var myLatlng = new google.maps.LatLng(65.000, 16.500 );
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var data = $(document.body).data('trafikk');
$(data).each(function(index, value){
var veiX = data[index].Coordinates.StartPoint.xCoord;
var veiY = data[index].Coordinates.StartPoint.yCoord;
var veiLatlng = new google.maps.LatLng(veiY, veiX);
var marker = new google.maps.Marker({
position: veiLatlng,
title: data[index].heading + " - " + data[index].messageType,
map: map
});;
});
}
jQuery(document).ready(function($){
// load the data
fetchData();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment