1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=fr"></script>
<script type="text/javascript" src="http://gmap3.touraineverte.com/js/gmap3/gmap3.min.js"></script>
</head>
<body>
<script type="text/javascript">$(function(){
/* Déclaration des variables globales */
var geocoder = new google.maps.Geocoder();
var addr, latitude, longitude;
/* Fonction chargée de géolocaliser l'adresse */
function geolocalise(){
/* Récupération du champ "adresse" */
addr = document.getElementById('adresse').value;
/* Tentative de géocodage */
geocoder.geocode( { 'address': addr}, function(results, status) {
/* Si géolocalisation réussie */
if (status == google.maps.GeocoderStatus.OK) {
/* Récupération des coordonnées */
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
/* Insertion des coordonnées dans les input text */
document.getElementById('lat').value = latitude;
document.getElementById('lng').value = longitude;
/* Appel AJAX pour insertion en BDD */
var sendAjax = $.ajax({
type: "POST",
url: 'insert-in-bdd.php',
data: 'lat='+latitude+'&lng='+longitude+'&adr='+addr,
success: handleResponse
});
}
function handleResponse(){
$('#answer').get(0).innerHTML = sendAjax.responseText;
}
});
}
$('#maCarteDeux').gmap3(
{
action:'init',
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
center: [48.839648,2.301490]
}
);
$('#bouton-alterner').click(function(){
$('#maCarteDeux').gmap3(
{
action:'getStreetView',
callback:function(panorama){
var visible = panorama.getVisible();
if (visible) {
panorama.setVisible(false);
} else {
var map = $(this).gmap3('get');
panorama.setPosition(map.getCenter());
panorama.setPov({
heading: 265,
zoom:1,
pitch:0
});
panorama.setVisible(true);
}
}
}
);
});
});
$('#maCarte').gmap3(
{
action: 'addMarker',
address: "place de l'étoile, paris",
map:{
center: true,
zoom: 14
},
marker:{
options:{
draggable: true
}
},
infowindow:{
options:{
content: 'Hello World !'
}
}
}
);
</script>
<br><br>
<input type="button" id="bouton-alterner" value="Alterner : Carte <-> StreetView" />
<div id="maCarteDeux" style="width:800px; height:500px;"></div>
</body>
</html> |
Partager