Created
February 19, 2019 10:30
-
-
Save khavari/e190aa5121d4d34aefad8d19f51c654e to your computer and use it in GitHub Desktop.
initialize map with draggable marker
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> | |
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®ion=IR&callback=initialize" async defer></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment