Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@harshamv
Created May 12, 2015 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshamv/2dd4a28e319974030485 to your computer and use it in GitHub Desktop.
Save harshamv/2dd4a28e319974030485 to your computer and use it in GitHub Desktop.
Maps Options
<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'), 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);
$('body').on('keydown', '#event_name', function(e) {
if (e.keyCode == 9) {
//e.preventDefault(); // prevents jumping :P
codeAddress();
}
});
function codeAddress() {
var address = $("#event_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('event_lat').value = marker.getPosition().lat().toFixed(6);
document.getElementById('event_lng').value = marker.getPosition().lng().toFixed(6);
google.maps.event.addListener(marker, "dragend", function () {
document.getElementById('event_lat').value = marker.getPosition().lat().toFixed(6);
document.getElementById('event_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