Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [google maps] pobieranie współrzędnych do inputa
eS...
post
Post #1





Grupa: Zarejestrowani
Postów: 367
Pomógł: 2
Dołączył: 4.03.2003
Skąd: C:/Windows/Temp

Ostrzeżenie: (0%)
-----


Witam
Mam mały problem z google maps. Potrzebuje zczytać latitude i longitude do inputa. Wszystko jest ok do momentu kiedy postawie markera z opcją draggable.

Chodzi o to aby po przesunięciu markera w inne miejsce , w inpucie pojawily sie latituda i longituda smile.gif

oto kod:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  4. <head>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  6. <title>Google Maps JavaScript API Example: Tile Detector</title>
  7. <script src="http://maps.google.com/maps?file=api&v=2"
  8. type="text/javascript"></script>
  9. <script type="text/javascript">
  10. function initialize() {
  11. if (GBrowserIsCompatible()) {
  12.  
  13. var map = new GMap2(document.getElementById("map_canvas"));
  14. map.setCenter(new GLatLng(37.88, -122.442626), 10);
  15. var marker = new GMarker(new GLatLng(37.88,-122.442626),{draggable:true});
  16. map.addOverlay(marker);
  17. map.addControl(new GSmallMapControl());
  18. map.addControl(new GMapTypeControl());
  19.  
  20. GEvent.addListener(marker,"click", function(overlay,latlng) {
  21. if (overlay) {
  22. // ignore if we click on the info window
  23. return;
  24. }
  25. var tileCoordinate = new GPoint();
  26. var tilePoint = new GPoint();
  27. var currentProjection = G_NORMAL_MAP.getProjection();
  28. tilePoint = currentProjection.fromLatLngToPixel(latlng, map.getZoom());
  29.  
  30.  
  31.  
  32.  
  33. // var myHtml = "Latitude: " + latlng.lat() + "<br/>Longitude: " + latlng.lng() +
  34. // "<br/>The Tile Coordinate is:<br/> x: " + tileCoordinate.x +
  35. //"<br/> y: " + tileCoordinate.y + "<br/> at zoom level " + map.getZoom();
  36. //map.openInfoWindow(latlng, myHtml);
  37. var myHtml = latlng.lat() + " , " +latlng.lng();
  38. document.getElementById('message').innerHTML = myHtml;
  39. });
  40.  
  41.  
  42. }
  43.  
  44. }
  45. </script>
  46. </head>
  47.  
  48. <body onload="initialize()" onunload="GUnload()">
  49. <div id="map_canvas" style="width: 500px; height: 300px">Loading ....</div>
  50. <div id="message"></div>
  51. </body>
  52. </html>


Prubowałem zamienić
  1. GEvent.addListener(marker,"click", function(overlay,latlng) {

na
  1. GEvent.addListener(marker,"dragend", function(overlay,latlng) {


niestety nic sad.gif


Proszę o pomoc

Pozdrawiam eska


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




kod funkcji, jaka wywolujesz dla zdarzenia, zwraca mi blad js:
Kod
a has no properties
[Break on this error] Oc.prototype=new pd;Oc.prototype.fromLatLngToPixel=function(a,b){var c=this,d=c....

Gdy wywale Twoj kod i dam zwyklego alerta, to on sie wykonuje niezaleznie czy marker jest draggable czy nie. Gdy jest draggable to ustawiam nie click a dragend.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
eS...
post
Post #3





Grupa: Zarejestrowani
Postów: 367
Pomógł: 2
Dołączył: 4.03.2003
Skąd: C:/Windows/Temp

Ostrzeżenie: (0%)
-----


Ok znalazlem coś w sieci i działa smile.gif

  1. if (GBrowserIsCompatible()) {
  2.  
  3. var map = new GMap2(document.getElementById("map"));
  4. map.addControl(new GLargeMapControl());
  5. map.addControl(new GMapTypeControl());
  6. var center = new GLatLng(50.0629726955118, 19.937782287597656);
  7. map.setCenter(center, 15);
  8.  
  9. marker = new GMarker(center, { draggable: true});
  10.  
  11. GEvent.addListener(marker, "dragstart", function() {
  12. map.closeInfoWindow();
  13. });
  14.  
  15. GEvent.addListener(marker, "dragend", function() {
  16. document.getElementById('lat').value = marker.getPoint().lat();
  17. document.getElementById('lng').value = marker.getPoint().lng();
  18. });
  19.  
  20. map.addOverlay(marker);
  21.  
  22. }


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 05:52