ugrás a tartalomhoz

Google maps koordináták db-be mentése

rob66 · 2013. Jan. 30. (Sze), 11.55
Hali,

A felhasználó által bejelölt Google Maps koordinátákat szeretném sql db-be menteni. Erre találtam is egy jó progit a neten, ami tökéletesen működik. Annyi kiegészítést szeretnék bele, hogy egy azonosító is mentésre kerüljön (amit a lenti kódba $a-val jelöltem), csak nem tudom, hogyan tudnám átadni azt a JS-nek.

Tudna valaki segíteni?
  1.     <title>Google Maps</title>  
  2.   
  3.       
  4.     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAPDUET0Qt7p2VcSk6JNU1sBSM5jMcmVqUpI7aqV44cW1cEECiThQYkcZUPRJn9vy_TWxWvuLoOfSFBw" type="text/javascript"></script>  
  5.   </head>  
  6.   <body onunload="GUnload()">  
  7.     
  8.     <?php  
  9.     $a = 100;  
  10.     ?>  
  11.    
  12.     <div id="map" style="width: 550px; height: 450px"></div>  
  13.     <a href="store.htm">Back to the tutorial page</a>  
  14.    
  15.    
  16.     <noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b>   
  17.       However, it seems JavaScript is either disabled or not supported by your browser.   
  18.       To view Google Maps, enable JavaScript by changing your browser options, and then   
  19.       try again.  
  20.     </noscript>  
  21.    
  22.    
  23.     <script type="text/javascript">  
  24.     //<![CDATA[  
  25.       
  26.     if (GBrowserIsCompatible()) {  
  27.    
  28.       var lastmarker;  
  29.       var iwform = 'Enter details:<br>'  
  30.                  + '<form action="#" onsubmit="process(this); return false" action="#">'  
  31.                  + '  <textarea name="data" rows="5" cols="40"><\/textarea><br>'  
  32.                  + '  <input type="submit" value="Submit" />'  
  33.                  + '<\/form>';  
  34.    
  35.       // == creates a draggable marker with an input form ==  
  36.       function createInputMarker(point) {  
  37.         var marker = new GMarker(point,{draggable:true, icon:G_START_ICON});  
  38.         GEvent.addListener(marker, "click"function() {  
  39.           lastmarker = marker;  
  40.           marker.openInfoWindowHtml(iwform);  
  41.         });  
  42.         map.addOverlay(marker);  
  43.         marker.openInfoWindowHtml(iwform);  
  44.         lastmarker=marker;  
  45.         return marker;  
  46.       }  
  47.    
  48.       // == creates a "normal" marker  
  49.       function createMarker(point,text) {   
  50.         var marker = new GMarker(point);  
  51.         GEvent.addListener(marker,"click"function() {  
  52.           marker.openInfoWindow(document.createTextNode(text));  
  53.         });  
  54.         map.addOverlay(marker);  
  55.         return marker;  
  56.       }  
  57.    
  58.       // == Display the map, with some controls and set the initial location   
  59.       var map = new GMap2(document.getElementById("map"),{draggableCursor:"default"});  
  60.       map.addControl(new GLargeMapControl());  
  61.       map.addControl(new GMapTypeControl());  
  62.       map.setCenter(new GLatLng(47.475, 19.062),6);         /* Induló koordináta + nagyítás*/  
  63.    
  64.       // == Listen for map click and add an input marker  
  65.       GEvent.addListener(map,"click",function(overlay,point){  
  66.         if (!overlay) {  
  67.           createInputMarker(point);  
  68.         }  
  69.       });  
  70.    
  71.       function process(form) {  
  72.         // == obtain the data  
  73.         var details = form.data.value;  
  74.         var lat = lastmarker.getPoint().lat();  
  75.         var lng = lastmarker.getPoint().lng();  
  76.         var url = "myserver.php?lat=" +lat+ "&lng=" +lng+ "&details="+details;  
  77.    
  78.         // ===== send the data to the server  
  79.         GDownloadUrl(url, function(doc) {    });    
  80.    
  81.         // == remove the input marker and replace it with a completed marker  
  82.         map.closeInfoWindow();  
  83.         var marker = createMarker(lastmarker.getPoint(),details);  
  84.         GEvent.trigger(marker,"click");  
  85.    
  86.       }  
  87.         
  88.     }  
  89.       
  90.     // display a warning if the browser was not compatible  
  91.     else {  
  92.       alert("Sorry, the Google Maps API is not compatible with this browser");  
  93.     }  
  94.    
  95.     // This Javascript is based on code provided by the  
  96.     // Community Church Javascript Team  
  97.     // http://www.bisphamchurch.org.uk/     
  98.     // http://econym.org.uk/gmap/  
  99.    
  100.     //]]>  
  101.     </script>  
  102.   </body>  
  103.    
  104. </html>  
 
1

<script

Poetro · 2013. Jan. 30. (Sze), 12.19
  1.   <script type="text/javascript">  
  2.   var $a = <?php print 100 ?>;  
  3.   //...  
  4.   </script>    
  5. </body>    
2

Köszi! Így már jó.

rob66 · 2013. Jan. 30. (Sze), 14.05
Köszi!

Így már jó.