Skip to content

Instantly share code, notes, and snippets.

@cenan
Created July 12, 2017 12:33
Show Gist options
  • Save cenan/e7b81ce3e952c70e9dc8106f4f505b28 to your computer and use it in GitHub Desktop.
Save cenan/e7b81ce3e952c70e9dc8106f4f505b28 to your computer and use it in GitHub Desktop.
geocode
var geocoder;
var map;
var marker;
function initialize() {
console.log("MAPS INITIALIZED");
var myLatlng = new google.maps.LatLng($("#event_latitude").val(), $("#event_longitude").val())
var mapOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false
}
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
marker = new google.maps.Marker({
position: myLatlng,
draggable: true,
map: map,
title: 'Etkinlik Noktası!',
icon: '/img/maymun-marker.png'
});
google.maps.event.addListener(marker, 'dragend', function () {
var point = marker.getPosition();
$('#event_latitude').val(point.lat());
$('#event_longitude').val(point.lng());
});
$("#input-address").blur(updateMaps);
//$("#input-address").on("keypress", updateMaps);
$("span.mark-location").click(updateMaps);
}
window._update_maps = function () {
updateMaps();
}
function updateMaps() {
var address = document.getElementById("input-address").value;
if (address && address.length > 0) {
geocoder.geocode({ 'address': address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var the_location = results[0].geometry.location;
map.setCenter(the_location);
marker.setPosition(the_location);
// Javascript//
map.setCenter(marker.position);
marker.setMap(map);
$('#event_latitude').val(the_location.lat());
$('#event_longitude').val(the_location.lng());
} else {
//alert("Aranan lokasyon bulunamadı :( Sebebi: " + status);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment