Created
June 22, 2023 12:14
-
-
Save muath-ye/303470fdb6210e274f95b77e2e385473 to your computer and use it in GitHub Desktop.
Here is an example of using google maps
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Google Maps Example</title> | |
<meta name="viewport" content="initial-scale=1.0"> | |
<meta charset="utf-8"> | |
<style> | |
#map { | |
height: 400px; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Choose a location on the map</h1> | |
<div id="map"></div> | |
<script> | |
function initMap() { | |
var map = new google.maps.Map(document.getElementById('map'), { | |
center: {lat: 37.7749, lng: -122.4194}, | |
zoom: 10 | |
}); | |
var marker = new google.maps.Marker({ | |
position: map.getCenter(), | |
map: map, | |
draggable: true | |
}); | |
google.maps.event.addListener(marker, 'dragend', function() { | |
document.getElementById('lat').value = marker.getPosition().lat(); | |
document.getElementById('lng').value = marker.getPosition().lng(); | |
}); | |
google.maps.event.addListener(map, 'click', function(event) { | |
marker.setPosition(event.latLng); | |
document.getElementById('lat').value = event.latLng.lat(); | |
document.getElementById('lng').value = event.latLng.lng(); | |
}); | |
} | |
</script> | |
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script> | |
<form> | |
<label for="lat">Latitude:</label> | |
<input type="text" id="lat" name="lat"> | |
<br> | |
<label for="lng">Longitude:</label> | |
<input type="text" id="lng" name="lng"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment