-
-
Save anonymous/52fb990631dd2fbfca2d to your computer and use it in GitHub Desktop.
Utilisation de l'API JS 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> | |
<style type="text/css"> | |
html, body { height: 100%; margin: 0; padding: 0; } | |
#map { height: 100%; } | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script type="text/javascript"> | |
var map; | |
var marker; | |
var marker2; | |
var myPosition; | |
function initMap() { | |
var myLatLng = {lat: -25.363, lng: 131.044}; | |
navigator.geolocation.getCurrentPosition(function(position) { | |
myPosition = {lat: position.coords.latitude, lng: position.coords.longitude}; | |
console.log(myPosition); | |
}); | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: {lat: -25.363, lng: 131.044}, | |
zoom: 6, | |
mapTypeId: google.maps.MapTypeId.SATELLITE, | |
disableDefaultUI: true | |
}); | |
marker = new google.maps.Marker({ | |
position: myLatLng, | |
map: map, | |
draggable:true, | |
title: 'Hello World!' | |
}); | |
marker2 = new google.maps.Marker({ | |
position: {lat: -27.363, lng: 138.044}, | |
map: map, | |
title: 'Hello World!' | |
}); | |
marker2.addListener('click', removeMarker); | |
} | |
function moveToMyPosition() { | |
map.panTo(myPosition); | |
} | |
function removeMarker() { | |
marker2.setMap(null); | |
} | |
</script> | |
<script async defer | |
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment