Skip to content

Instantly share code, notes, and snippets.

@shohel
Created October 4, 2015 09:34
Show Gist options
  • Save shohel/6599f8b96e9820dd8e4a to your computer and use it in GitHub Desktop.
Save shohel/6599f8b96e9820dd8e4a to your computer and use it in GitHub Desktop.
<script>
function executeMap(x =''){
var marker, map;
function initialize() {
var myLatlng = new google.maps.LatLng(29.350578853144864, 47.98828125);
var mapOptions = {
zoom: 10,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'+x), mapOptions);
marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
});
}
}
$(function() {
initialize();
google.maps.event.addListener(map, 'click', function(event) {
var lat=event.latLng.lat();
var lng=event.latLng.lng();
//$('#latlng').val(lat+', '+lng);
$('#lat'+x).val(lat);
$('#long'+x).val(lng);
marker.animateTo(event.latLng);
});
});
}
executeMap();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment