Created
September 20, 2016 05:17
-
-
Save harshamv/18ff6dcbf576636da199cd99f1baea94 to your computer and use it in GitHub Desktop.
Nomad Google Maps Js
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
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBkg1vwaBHSPzbhrQoyThpxYmZF24Py-ok"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$("#venue_country_id").change(function(){ | |
var country_id = $(this).val(); | |
console.log(country_id); | |
$.ajax({ | |
type: "get", | |
url: "/admin/regions/get_regions/"+country_id, | |
//data: country_id, | |
success:function(data){ | |
var options = ''; | |
$.each(data, function (key,value) { | |
options += '<option value="'+value.id+'">'+value.name+'</option>'; | |
console.log(value.id + " " +value.name) | |
}); | |
//$("#venue_region_id").select2("destroy"); | |
//$("#venue_region_id").select2("data", data, true); | |
$('#venue_region_id').empty(); | |
$('#venue_region_id').select2("val", ""); | |
//$('#venue_region_id').select2("placeholder", "Select a Region"); | |
$('#venue_region_id').append(options); | |
} | |
}); | |
}); | |
$("#venue_region_id").change(function(){ | |
var region_id = $(this).val(); | |
console.log(region_id); | |
$.ajax({ | |
type: "get", | |
url: "/admin/cities/get_cities/"+region_id, | |
//data: country_id, | |
success:function(data){ | |
var options = ''; | |
$.each(data, function (key,value) { | |
options += '<option value="'+value.id+'">'+value.name+'</option>'; | |
console.log(value.id + " " +value.name) | |
}); | |
//$("#venue_region_id").select2("destroy"); | |
//$("#venue_region_id").select2("data", data, true); | |
$('#venue_city_id').empty(); | |
$('#venue_city_id').select2("val", ""); | |
//$('#venue_region_id').select2("placeholder", "Select a Region"); | |
$('#venue_city_id').append(options); | |
} | |
}); | |
}); | |
}); | |
</script> | |
<script type="text/javascript"> | |
var map; | |
var geocoder; | |
var service; | |
var mapOptions = { | |
center: new google.maps.LatLng(12.971599, 77.594563), | |
zoom: 14, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
} | |
var marker; | |
function initialize() { | |
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); | |
geocoder = new google.maps.Geocoder(); | |
//codeAddress(); | |
google.maps.event.addListener(map, 'click', function (event) { | |
map.panTo(event.latLng); | |
map.setCenter(event.latLng); | |
createMarker(event.latLng); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
// $("#gmaps").submit(function () { | |
// codeAddress(); | |
// return false; | |
// }); | |
$('body').on('keydown', '#venue_name', function(e) { | |
if (e.keyCode == 9) { | |
//e.preventDefault(); // prevents jumping :P | |
codeAddress(); | |
} | |
}); | |
// //setup before functions | |
// var typingTimer; //timer identifier | |
// var doneTypingInterval = 4000; //time in ms, 5 second for example | |
// | |
// //on keyup, start the countdown | |
// $('#venue_name').keyup(function(){ | |
// clearTimeout(typingTimer); | |
// typingTimer = setTimeout(codeAddress, doneTypingInterval); | |
// }); | |
// | |
// //on keydown, clear the countdown | |
// $('#venue_name').keydown(function(){ | |
// clearTimeout(typingTimer); | |
// }); | |
function codeAddress() { | |
var address = $("#venue_name").val(); | |
fetchWiki(address); | |
geocoder.geocode({ | |
'address': address | |
}, function (results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
map.setCenter(results[0].geometry.location); | |
createMarker(results[0].geometry.location); | |
console.log(results[0]); | |
} else { | |
alert('Please enter the Venue name! Error: ' + status); | |
} | |
}); | |
} | |
function createMarker(latLng) { | |
if ( !! marker && !! marker.setMap) marker.setMap(null); | |
marker = new google.maps.Marker({ | |
map: map, | |
position: latLng, | |
draggable: true | |
}); | |
document.getElementById('venue_lat').value = marker.getPosition().lat().toFixed(6); | |
document.getElementById('venue_lng').value = marker.getPosition().lng().toFixed(6); | |
google.maps.event.addListener(marker, "dragend", function () { | |
document.getElementById('venue_lat').value = marker.getPosition().lat().toFixed(6); | |
document.getElementById('venue_lng').value = marker.getPosition().lng().toFixed(6); | |
}); | |
} | |
function fetchWiki(name){ | |
console.log(name) | |
$.ajax({ | |
type: "get", | |
//dataType: 'jsonp', | |
url: "http://play.mink7.com/gmaps/index.php?query="+name, | |
success:function(data){ | |
console.log(data); | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Google Maps Circle