google api polygone

Eléphanteau du PHP | 33 Messages

06 mars 2017, 11:16

Bonjour, voila j'ai vu qu'on pouvait créer un rectangle modifiable de cette façon:

Code : Tout sélectionner

<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <title>Rectangle Events</title> <style> html, body { height: 100%; margin: 0; padding: 0; } #map { height: 100%; } </style> </head> <body> <div id="map"></div> <script> // This example adds a user-editable rectangle to the map. // When the user changes the bounds of the rectangle, // an info window pops up displaying the new bounds. var rectangle; var map; var infoWindow; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {lat: 44.5452, lng: -78.5389}, zoom: 9 }); var bounds = { north: 44.599, south: 44.490, east: -78.443, west: -78.649 }; // Define the rectangle and set its editable property to true. rectangle = new google.maps.Rectangle({ bounds: bounds, editable: true, draggable: true }); rectangle.setMap(map); // Add an event listener on the rectangle. rectangle.addListener('bounds_changed', showNewRect); // Define an info window on the map. infoWindow = new google.maps.InfoWindow(); } // Show the new coordinates for the rectangle in an info window. /** @this {google.maps.Rectangle} */ function showNewRect(event) { var ne = rectangle.getBounds().getNorthEast(); var sw = rectangle.getBounds().getSouthWest(); var contentString = '<b>Rectangle moved.</b><br>' + 'New north-east corner: ' + ne.lat() + ', ' + ne.lng() + '<br>' + 'New south-west corner: ' + sw.lat() + ', ' + sw.lng(); // Set the info window's content and position. infoWindow.setContent(contentString); infoWindow.setPosition(ne); infoWindow.open(map); } </script> <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&signed_in=true" async defer> </script> </body> </html>
Et du coup pour enregistrer les données on pouvais directement récupéré comme ceci :

Code : Tout sélectionner

var valider = function(){ // quand on clique sur le bouton Valider, cette fonction va s'executer // Définition des variables pour AJAX var oXhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); oXhr.onreadystatechange = function(){ if( oXhr.readyState === 4 && oXhr.status === 200){ alert(oXhr.responseText); } }; // On récupère les valeurs des select var north_rect = document.getElementById('north_rect').textContent; var south_rect = document.getElementById('south_rect').textContent; var east_rect = document.getElementById('east_rect').textContent; var west_rect = document.getElementById('west_rect').textContent; var _id_cap = document.getElementById('_id_cap').textContent; // On définit la méthode à utiliser et l'url de la page à charger oXhr.open('POST', 'enregistrement.php', true); oXhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // On définit quelles variables envoyer oXhr.send("north_rect="+north_rect+"&south_rect="+south_rect+"&east_rect="+east_rect+"&west_rect="+west_rect+"&_id_cap="+_id_cap); };
Et j'aurais aimé faire la même chose mais avec un polygone, je pensais faire de cette façon mais j'arrive suelement a affiché le polygone, c'est pour tout ce qui est ajax que je n'y arrive pas :

Code : Tout sélectionner

var map; var infoWindow; function initMap() { map = new google.maps.Map(document.getElementById('map'), { zoom: 5, center: {lat: 24.886, lng: -70.268}, mapTypeId: google.maps.MapTypeId.TERRAIN }); // Define the LatLng coordinates for the polygon. var triangleCoords = [ {lat: 25.774, lng: -80.190}, {lat: 18.466, lng: -66.118}, {lat: 32.321, lng: -64.757} ]; // Construct the polygon. var bermudaTriangle = new google.maps.Polygon({ paths: triangleCoords, strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 3, fillColor: '#FF0000', fillOpacity: 0.35 }); bermudaTriangle.setMap(map); // Add a listener for the click event. bermudaTriangle.addListener('click', showArrays); infoWindow = new google.maps.InfoWindow; } function showArrays(event) { // Since this polygon has only one path, we can call getPath() to return the // MVCArray of LatLngs. var latitude=polygone.getPath(). var _id_cap ='<?php echo $_id_cap ?>'; var contentString = '<b>Bermuda Triangle polygon</b><br>' + 'Clicked location: <br>' + '<span id="lat_point">'+ event.latLng.lat() + ',' + '<span id="lng_point">' + event.latLng.lng() + '<br>'; // Replace the info window's content and position. infoWindow.setContent(contentString); infoWindow.setPosition(event.latLng); infoWindow.open(map); }
et le code ajax :

Code : Tout sélectionner

var validation = function(){ // quand on clique sur le bouton Valider, cette fonction va s'executer // Définition des variables pour AJAX var oXhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); oXhr.onreadystatechange = function(){ if( oXhr.readyState === 4 && oXhr.status === 200){ alert(oXhr.responseText); } }; // On récupère les valeurs des select var lat_point = document.getElementById('lat_point').textContent; // On récupère les valeurs des select var long_point = document.getElementById('lng_point').textContent; var _id_cap = document.getElementById('_id_cap').textContent; // On définit la méthode à utiliser et l'url de la page à charger oXhr.open('POST', 'enregistrement.php', true); oXhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // On définit quelles variables envoyer oXhr.send("&_id_cap="+_id_cap+"&latitude_centre="+lat_point+"&longitude_centre="+long_point); };
je pense que ce code doit être faux mais je sais pas trop comment m'y prendre

Merci bien ;)

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

06 mars 2017, 16:15

Modération :
Le multipostage est interdit sur le forum.

Ce sujet a été verrouillé et sera supprimé sous peu.
Des réponses peuvent être apportées à cette adresse :
javascript-ajax/recuperer-variables-dan ... 77975.html .
Il en faut peu pour être heureux ......