Created
July 1, 2012 12:17
-
-
Save eftakhairul/3028253 to your computer and use it in GitHub Desktop.
Raw Javascript of Crime Map at Change App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map; | |
var saveLat = 0; | |
var saveLng = 0; | |
var lat = 23.71003142406148; | |
var lon = 90.407231156616290; | |
var image = "<?php echo site_url('assets/images/pirates.png')?>"; | |
if (!navigator.geolocation) { | |
alert('Get a better browser'); | |
} | |
navigator.geolocation.getCurrentPosition(function(position) | |
{ | |
lat = position.coords.latitude; | |
lon = position.coords.longitude; | |
init(); | |
var total = <?php echo count($locations) ?>; | |
var locations = <?php echo json_encode($locations) ?>; | |
for(var x = 0; x <total; x++) | |
{ | |
var infoMessage = locations[x]['note']+'-'+ locations[x]['create_date']; | |
placeMarker(new google.maps.LatLng(locations[x]['latitude'],locations[x]['longitude']), infoMessage); | |
} | |
}); | |
function init() | |
{ | |
var myLatlng = new google.maps.LatLng(lat,lon); | |
var myOptions = { | |
zoom: 8, | |
center: myLatlng, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
} | |
map = new google.maps.Map(document.getElementById("mapdiv"), myOptions); | |
google.maps.event.addListener(map, 'click', function(event) { | |
//saving data to database | |
saveLat = event.latLng.lat(); | |
saveLng = event.latLng.lng(); | |
$( "#dialog" ).dialog(); | |
}); | |
} | |
function placeMarker(location, note) | |
{ | |
var marker = new google.maps.Marker({ | |
position: location, | |
icon: image, | |
map: map, | |
title: note | |
}); | |
// var infowindow = new google.maps.InfoWindow({ | |
// content: note | |
// }); | |
// | |
// google.maps.event.addListener(marker, 'click', function () { | |
// infowindow.open(map, maker); | |
// }); | |
map.setCenter(location); | |
} | |
function savaMapLocation(lat, lng, message) { | |
$.ajax({ | |
url: '/map/saveCrimeLocation', | |
type: 'POST', | |
dataType: 'json', | |
data: {'latitude': lat, 'longitude': lng, 'note': message}, | |
success: function(data) { | |
} | |
}); | |
} | |
$('#submitButton').click(function() { | |
$( "#dialog" ).dialog('close'); | |
var crimeMessage = $('#crimeMessage').val(); | |
// var currentTime = new Date() | |
// var month = currentTime.getMonth(); | |
// var day = currentTime.getDate(); | |
// var year = currentTime.getFullYear(); | |
// var date = year +' - '+ month +' - '+ day; | |
placeMarker(new google.maps.LatLng(saveLat, saveLng), crimeMessage); | |
savaMapLocation(saveLat, saveLng, crimeMessage); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment