Skip to content

Instantly share code, notes, and snippets.

@khavari
Created February 19, 2019 10:30
Show Gist options
  • Save khavari/e190aa5121d4d34aefad8d19f51c654e to your computer and use it in GitHub Desktop.
Save khavari/e190aa5121d4d34aefad8d19f51c654e to your computer and use it in GitHub Desktop.
initialize map with draggable marker
<script>
let map;
function initialize () {
const lat = 35.731671;
const lng = 51.380317;
const zoom = 17;
map = new google.maps.Map(document.getElementById('google_map'), {
center: {lat: lat, lng: lng},
zoom: zoom,
mapTypeControl: false
});
var marker = new google.maps.Marker({
position: {lat: lat, lng: lng},
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
title: 'Drag to get location'
});
marker.addListener('dragend', function (event) {
const lat = event.latLng.lat();
const lng = event.latLng.lng();
console.log(lat);
console.log(lng);
console.log("-----------------------");
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAHcESNVFvBcfWU9rmCxdRDGG5-pWrLrnY&libraries=places&language=fa&region=IR&callback=initialize" async defer></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment